tkinter()--Label and Button

Label & Button 标签和按钮

-窗口主题框架

-窗口内容

需求:

tkinter()--Label and Button_第1张图片

import tkinter as tk

window = tk.Tk()  #### 窗口object
window.title('my window')
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('u 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()

 

你可能感兴趣的:(python,python,tkinter)