gpt4 book ai didi

python - blender 中奇怪的 Material 故障

转载 作者:太空宇宙 更新时间:2023-11-03 18:03:19 24 4
gpt4 key购买 nike

我使用 Tkinter 制作了一个带有一些按钮的简单窗口。一个按钮一开始处于禁用状态,但我希望在按下另一个按钮后它再次变为正常状态。那么如何在代码运行时更改按钮的属性呢?

from tkinter import *

def com():
print ('activate')

def win():
window = Tk()
window.geometry ('500x500')
b1 = Button(text = 'Disabled', pady = '10', padx = '10', state = DISABLED)
b1.place(x=100, y=10)
b2 = Button(text = 'activate', pady = '10', padx = '10', command=com)
b2.place(x=10, y=10)
window.mainloop

win()

最佳答案

您必须使用<buttonname>.config(state=STATE)命令,状态为:

  • 正常(默认)
  • 活跃
  • 已禁用

Source我冒昧地创建编辑代码来测试这一点,它确实有效,见下文!

from Tkinter import *

def com1():
print ('activate')
b1.config(state = ACTIVE)
b2.config(state = DISABLED) #toggles the buttons

def com2():
print('de-activate')
b1.config(state = DISABLED)
b2.config(state = ACTIVE) #toggles the buttons

def win():
global b1
global b2 #This is to allow passing b1 and b2 to com1 and com2, but may not be the most "efficient" way to do this...
window = Tk()
window.geometry ('500x500')
b1 = Button(text = 'Disabled', pady = '10', padx = '10', state = DISABLED, command = com2) #command com2 added here
b1.place(x = 100, y = 10)
b2 = Button(text = 'activate', pady = '10', padx = '10', command = com1) #com changed to com1
b2.place(x = 10, y = 10)

window.mainloop()

win()

关于python - blender 中奇怪的 Material 故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27342016/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com