Label & Button 标签和按钮

import tkinter as tk

window = tk.Tk()
window.title("daxiangcai's title")
window.geometry('800x400')  # 窗口大小

onhit = False
labeltext = tk.StringVar()


def changelabeltext():
    global onhit
    if onhit == False:
        onhit = True
        labeltext.set('you hit this button')
    else:
        onhit = False
        labeltext.set('')


l = tk.Label(window, textvariable=labeltext, bg='green', font=('Arial', 12), width=15, height=2)  # 标签
l.pack()

b = tk.Button(window, text="first button", width=15, height=2, command=changelabeltext)  # 按钮
b.pack()

window.mainloop()  # 不断更新窗口

 

posted @ 2022-07-05 20:14  树叶本子  阅读(60)  评论(0)    收藏  举报