Home Article Practice python 击鼓传花

python 击鼓传花

2025-01-14 19:21  views:118  source:dyq2785973417    

import tkinter as tk
root=tk.Tk()
root.geometry("300x300")
s=0
cs=1
flag=True
def fun():
global s
if flag:
x.set(s)
s+=1
root.after(500,fun)
if s==5:
s=0
def ks(event):
global flag,cs
flag=True
if cs==1:
cs+=1
fun()
def zt(event):
global flag,cs
cs=1
flag=False
x=tk.IntVar()
r1=tk.Radiobutton(root,text="金",variable=x,value=0)
r1.place(relx=0.4,rely=0.1)
r2=tk.Radiobutton(root,text="木",variable=x,value=1)
r2.place(relx=0.5,rely=0.2)
r3=tk.Radiobutton(root,text="水",variable=x,value=2)
r3.place(relx=0.45,rely=0.3)
r4=tk.Radiobutton(root,text="火",variable=x,value=3)
r4.place(relx=0.3,rely=0.3)
r5=tk.Radiobutton(root,text="土",variable=x,value=4)
r5.place(relx=0.25,rely=0.2)
x.set(0)
b1=tk.Button(root,text="开始")
b1.pack(side="bottom")
b1.bind("<ButtonPress>",ks)
b2=tk.Button(root,text="暂停")
b2.pack(side="bottom")
b2.bind("<ButtonPress>",zt)
b3=tk.Button(root,text="退出",command=root.destroy)
b3.pack(side="bottom")
root.mainloop()



Disclaimer: The above articles are added by users themselves and are only for typing and communication purposes. They do not represent the views of this website, and this website does not assume any legal responsibility. This statement is hereby made! If there is any infringement of your rights, please contact us promptly to delete it.

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)