【发布时间】:2021-04-29 09:05:45
【问题描述】:
我正在制作一个 Tkinter GUI,其中包含打开更多窗口的按钮。问题是第二个窗口上的按钮应该更改文本/颜色(指示 LED 关闭/打开的东西)但在窗口关闭并再次打开之前它不会更新。
有人知道如何在不关闭窗口的情况下更新它吗?
def open_relais():
relais = Toplevel()
relais.title('first window')
relais.geometry('800x480')
LED = Button(relais,text='LED',command=LED1,bg='grey89',fg='black',padx=10,pady=10)
LED.pack(pady=50)
#led knop kleur
if ledstate == 0:
LED.config(bg='red')
else:
LED.config(bg='green')
close_button = Button(relais, text='close window', command=relais.destroy).pack()
def LED1():
global ledstate
if ledstate == 0:
ledstate = 1
bus.write_byte_data(DEVICE,OLATA,ledstate)
print(ledstate)
else:
ledstate = 0
bus.write_byte_data(DEVICE,OLATA,ledstate)
print(ledstate)
button1=Button(menu,text='item 1 in horizontal',command=open_relais,bg='grey89',fg='black',padx=10,pady=10)
button1.grid(row=0,column=0,padx=23,pady=15,sticky='nsew')
问题可能是我在“def”函数中打开了第二个窗口。 任何帮助表示赞赏
【问题讨论】:
标签: python windows tkinter button