[英]Wierd material glitch in blender
我在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)
命令,其中STATE可以是:
来源我随意创建编辑代码来测试它,并且它确实有效,请参见下文!
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.