我需要有一个最初禁用的按钮,以后启用事件。我有一个相当大的应用程序正在工作,除非我无法将状态更改为按钮。请不要告诉我,我需要彻底重塑代码。这是离开我使用的显着结构的所有代码中的一条。 ReadPort实际上是从'after'后面调用的,但是在这里按下按钮模拟它。如何将画布按钮状态设置为正常(Python 3)
我已阅读关于此主题的所有帮助,并尝试了答案。每个产生的Python语句和错误都是在这个完整的应用程序中,在所有尝试改变按钮状态的尝试中都失败了。请让我知道如何解决这个问题。
#!/usr/bin/python 3
from tkinter import *
def ReadPort():
global VSM_Button
# AttributeError: 'NoneType' object has no attribute 'config'
## VSM_Button.config(state="normal")
# AttributeError: 'NoneType' object has no attribute 'configure'
## VSM_Button.configure(state="normal")
# TypeError: 'NoneType' object does not support item assignment
## VSM_Button['state'] = 'normal'
# AttributeError: 'NoneType' object has no attribute 'configure'
## VSM_Button.configure(state=NORMAL)
# ??? How do I set the button state to 'normal' ?
pass
class Application:
def __init__(self, master):
#global VSM_Button # seems unnecessary. Same errors in or out.
frame = Frame(master)
frame.pack()
Button(frame, text='Press Me', width = 10, command=ReadPort).pack()
VSM_Button = Button(frame, text='Disabled', width = 10, state = DISABLED).pack()
pass # end def __init__
pass # end class Application
root = Tk()
root.wm_title('Button')
app = Application(master=root)
root.mainloop()
本网站上可能有数百个问题与答案有关,错误“NoneType”对象没有任何属性。 –