其他分享
首页 > 其他分享> > Label & Button 标签和按钮

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()  # 不断更新窗口

 

标签:False,labeltext,changelabeltext,Button,onhit,window,tk,按钮,Label
来源: https://www.cnblogs.com/daxiangcai/p/16448491.html