程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python implementation roulette lottery applet (with interface)

編輯:Python

Effect display :

  Specific needs :

1. After you click the start button , The disc begins to turn ; Click end , Pop up the corresponding prize

2. After the disc starts to rotate , Stop at each prize 0.2 second

2. There are author and exit options in the menu item ; Select the author option , Pop up the author's name , Click exit to exit the program

Source code :

import tkinter as tk
import time
import threading
import tkinter.messagebox as tkbox
win = tk.Tk()
win.title(" Lucky draw ")
win.geometry("400x400")
bg = "white"
sleep = True
vary_sleep = True
text1 = tk.Label(win,text=" Prize 1:\n Cartoon water cup ",bg=bg,height=3,width=8)
text1.place(x=30,y=20)
text2 = tk.Label(win,text=" Prize 2:\n Weighing scale ",bg=bg,height=3,width=8)
text2.place(x=115,y=20)
text3 = tk.Label(win,text=" Prize 3:\n Mong tsai QQ sugar ",bg=bg,height=3,width=8)
text3.place(x=200,y=20)
text4 = tk.Label(win,text=" Prize 4:\n Secret hamburger ",bg=bg,height=3,width=8)
text4.place(x=285,y=20)
text5 = tk.Label(win,text=" Prize 5:\n Good juice ",bg=bg,height=3,width=8)
text5.place(x=285,y=85)
text6 = tk.Label(win,text=" Prize 6:\n Wang sweetheart dumplings ",bg=bg,height=3,width=8)
text6.place(x=285,y=150)
text7 = tk.Label(win,text=" Prize 7:\n Summer vacation secret volume ",bg=bg,height=3,width=8)
text7.place(x=285,y=215)
text8 = tk.Label(win,text=" Prize 8:\n Wangzai suit ",bg=bg,height=3,width=8)
text8.place(x=285,y=280)
text9 = tk.Label(win,text=" Prize 9:\n Big force fight ",bg=bg,height=3,width=8)
text9.place(x=200,y=280)
text10 = tk.Label(win,text=" Prize 10:\n Tomahawk steak ",bg=bg,height=3,width=8)
text10.place(x=115,y=280)
text11 = tk.Label(win,text=" Prize 11:\n Have a holiday ",bg=bg,height=3,width=8)
text11.place(x=30,y=285)
text12 = tk.Label(win,text=" Prize 12:\n Move to Yunnan ",bg=bg,height=3,width=8)
text12.place(x=30,y=215)
text13 = tk.Label(win,text=" Prize 13:\n Extra points in college entrance examination ",bg=bg,height=3,width=8)
text13.place(x=30,y=150)
text14 = tk.Label(win,text=" Prize 14:\n One piece ",bg=bg,height=3,width=8)
text14.place(x=30,y=85)
text_list = [text1,text2,text3,text4,text5,text6,text7,text8,text9,text10,text11,text12,text13,text14]
def menu():
tkbox.showinfo(" author ", " Li goudan ")
mainmenu = tk.Menu(win)
filemenu = tk.Menu(mainmenu,tearoff=False)
mainmenu.add_cascade (label=" operation ",menu=filemenu)
filemenu.add_command (label=" author ",command=menu)
filemenu.add_command (label=" sign out ",command=win.quit)
win.config (menu=mainmenu)
def end_code():
global vary_sleep
vary_sleep = False
def rounds():
global sleep,vary_sleep
if sleep==True:
x = 0
while True:
if vary_sleep==False:
value = text_list[x-1]['text']
tkbox.showinfo(" Thank you for your attention "," Congratulations! :{}".format(value))
tkbox.showinfo(" If it helps you ", " Please go to a certain place Get your prize !!!")
return
else:
time.sleep(0.2)
for i in text_list:
i['bg'] = "white"
text_list[x]['bg'] = 'red'
x += 1
if x >= len(text_list):
x = 0
else:
return
def start():
t = threading.Thread(target=rounds)
t.start()
start_button = tk.Button(win,text=" Start ",height=4,width=10,command=start)
start_button.place(x=105,y=125)
start_button = tk.Button(win,text=" end ",height=4,width=10,command=end_code)
start_button.place(x=195,y=125)
win.mainloop()


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved