我需要有一個最初禁用的按鈕,以後啓用事件。我有一個相當大的應用程序正在工作,除非我無法將狀態更改爲按鈕。請不要告訴我,我需要徹底重塑代碼。這是離開我使用的顯着結構的所有代碼中的一條。 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」對象沒有任何屬性。 –