import tkinter as tk
# tkinter 用来写用户界面的工具
# as 重命名
# 1。初始化,新建一个对象
myWindow = tk.Tk()
# 2.窗口的大小, 通过一个元组给一个宽度和高度()
myWindow.geometry("500x500")
# 3.软件的标题
myWindow.title("元气骑士")
a = 0
def click():
global a # 全局变量
a = a+1
if a >= 2:
a = 0
la["text"] = "点赞人数%d"%a
if a == 0:
la['text']="秀"
# la["text"] = "点赞人数1"
# 一,标签 Label
la = tk.Label(
myWindow,
text = "秀",
font = (None, 30),
bg = "pink", # back ground
fg = "black", # front ground
width = 20, # 宽度
height = 10,
)
# 放置标签
la.pack()
# 二,按钮 Button
btn = tk.Button(
myWindow,
text = "点赞",
bg = "black",
fg = "white",
font=(None, 20),
width = 5,
height = 2,
command = click,
)
# 放置标签
btn.pack()
# 4.循环刷新
myWindow.mainloop()
runze -学习tkinter
最新推荐文章于 2024-06-07 07:15:00 发布