用python实现一个按钮点击计数器
先导入tkinter模块,再建立一个窗口,然后装入标签,按钮等组件。
import tkinter as tk
win = tk.Tk()
win.title('按钮点击计数器')
win.geometry('600x500+200+200')
counter = 0 #计数器开始计数的数字为0
def button_click():
global counter
counter += 1
label.config(text=str(counter))
label = tk.Label(win, text="0",font=('隶书','66'),width=10,height=10)
button = tk.Button(win, text="点我试试看!",bg='#90F0F0',width=20,height=50, command=button_click)
label.pack(side='left')
button.pack(side='right')
win.mainloop()