Tkinter 做简单的窗口视窗 (GUI 莫烦 Python 教程) 2 Label & Button 标签和按钮

import tkinter as tk
window = tk.Tk()
window.title('my windows')
window.geometry('200x100')

var = tk.StringVar()
l = tk.Label(window, textvariable=var, bg='green', font=('Arial', 12), width=15, height=2)
l.pack()

on_hit = False
def hit_me():
    global on_hit
    if on_hit == False:
        on_hit = True
        var.set('you hit me')
    else:
        on_hit = False
        var.set('')

b =  tk.Button(window, text='hit me', width=15,height=2, command=hit_me)

b.pack()


window.mainloop()

猜你喜欢

转载自blog.csdn.net/pySVN8A/article/details/81482951