Python 3.10.4
Jag har skapat ett fönster med några knappar på.
Kod: Markera allt
window = tk.Tk()
window.geometry('380x600')
window.title('DS Manual 4-20mA Trim')
window.resizable(False, False)
btn_Start = tk.Button(window, text = 'Start', width = 7, font = fnt.Font(size = 16), command = Start_Test, state = NORMAL).pack(pady = 7)
btn_Next = tk.Button(window, text = 'Next', width = 7, font = fnt.Font(size = 16), command = Next_Test , state = DISABLED).pack(pady = 7)
btn_Up = tk.Button(window, text = 'Up', width = 7, font = fnt.Font(size = 16), command = Up_Test , state = DISABLED).pack(pady = 7)
btn_Down = tk.Button(window, text = 'Down', width = 7, font = fnt.Font(size = 16), command = Down_Test , state = DISABLED).pack(pady = 7)
btn_Stop = tk.Button(window, text = 'Stop', width = 7, font = fnt.Font(size = 16), command = Stop_Test , state = DISABLED).pack(pady = 7)
txt = tk.Text(window, height = 10, width = 40)
txt.config(state = NORMAL)
txt.pack(expand = True)
window.mainloop()
Kod: Markera allt
def Start_Test():
global btn_Start
global btn_Next
global btn_Up
global btn_Down
global btn_Stop
... lite småsaker
btn_Start['state'] = tk.DISABLED # RAD 136
btn_Next ['state'] = tk.NORMAL
btn_Up ['state'] = tk.DISABLED
btn_Down ['state'] = tk.DISABLED
btn_Stop ['state'] = tk.NORMAL
File "C:\Users\Torsten\AppData\Local\Programs\Python\Python310\DS Manual trim.py", line 136, in Start_Test
btn_Start['state'] = tk.DISABLED
TypeError: 'NoneType' object does not support item assignment
Jag har testat med <btn_Start['state'] = DISABLED> utan skillnad.
Om jag INTE utför denna disable/enable fungerar allt som planerat.
Jag har testat att deklarera alla knapparna som globala i starten av programmet men samma fel.
Vad tusan gör jag fel?
Jag gör exakt som det står när jag googlar "python button enable".