小项目:单击按钮,标签字符串改变
修改莫凡Python代码:莫烦Python
import tkinter as tk window = tk.Tk() window.title('666') window.geometry('300x100') var=tk.StringVar() var.set('first Button') theLabel=tk.Label(window,textvariable=var, fg='yellow',bg='blue', font=('宋体',15),width=20,height=2) theLabel.pack() hi_go=False def first_Button(): global hi_go if not hi_go: hi_go = True var.set('') else: hi_go = False var.set('first Button') theButton=tk.Button(window,text='button001',command=first_Button, width=15,height=2) theButton.pack() window.mainloop()