0
當使用面向對象的編寫代碼的方式時,我似乎無法使用函數更改GUI中的按鈕文本。使用函數來更改面向對象的tkinter代碼
我能夠在控制檯中打印它,當我單擊按鈕但我無法更改GUI。
我可以再次以非面向對象的方式完成這項工作。
我真的很感謝所有幫助我一直停留在此的方式來長笑
感謝
from tkinter import *
import tkinter as tk
# tk class open
class main(tk.Tk):
def __init__(self, *args):
tk.Tk.__init__(self, *args)
main.minsize(self, width=250, height=300)
frame = tk.Frame(self, bg='red')
frame.pack(side='left', fill='both', expand=True)
self.button = Button(frame, text='heloo', command=self.change)
self.button.pack()
def change(self):
self.button.configure(self, text='now1')
self.button.pack()
print('This works but does not change the button in the GUI')
app = main()
app.mainloop()