当前位置:   article > 正文

Python实现轮盘抽奖小程序(带界面)_python盲盒抽奖程序代码带界面

python盲盒抽奖程序代码带界面

效果展示:

 具体需求:

1.点击开始按钮后,轮盘开始转动;点击结束后,弹窗弹出对应奖品

2.轮盘开始转动后,在每个奖品停留0.2秒

2.菜单项中有作者和退出选项;选择作者选项,弹窗弹出作者姓名,点击退出程序后退出程序

源码:

  1. import tkinter as tk
  2. import time
  3. import threading
  4. import tkinter.messagebox as tkbox
  5. win = tk.Tk()
  6. win.title("幸运抽奖")
  7. win.geometry("400x400")
  8. bg = "white"
  9. sleep = True
  10. vary_sleep = True
  11. text1 = tk.Label(win,text="奖品1:\n卡通水杯",bg=bg,height=3,width=8)
  12. text1.place(x=30,y=20)
  13. text2 = tk.Label(win,text="奖品2:\n体重秤",bg=bg,height=3,width=8)
  14. text2.place(x=115,y=20)
  15. text3 = tk.Label(win,text="奖品3:\n旺仔QQ糖",bg=bg,height=3,width=8)
  16. text3.place(x=200,y=20)
  17. text4 = tk.Label(win,text="奖品4:\n秘制小汉堡",bg=bg,height=3,width=8)
  18. text4.place(x=285,y=20)
  19. text5 = tk.Label(win,text="奖品5:\n好果汁吃",bg=bg,height=3,width=8)
  20. text5.place(x=285,y=85)
  21. text6 = tk.Label(win,text="奖品6:\n王甜心饺子",bg=bg,height=3,width=8)
  22. text6.place(x=285,y=150)
  23. text7 = tk.Label(win,text="奖品7:\n暑假密卷",bg=bg,height=3,width=8)
  24. text7.place(x=285,y=215)
  25. text8 = tk.Label(win,text="奖品8:\n旺仔套装",bg=bg,height=3,width=8)
  26. text8.place(x=285,y=280)
  27. text9 = tk.Label(win,text="奖品9:\n大逼斗",bg=bg,height=3,width=8)
  28. text9.place(x=200,y=280)
  29. text10 = tk.Label(win,text="奖品10:\n战斧牛排",bg=bg,height=3,width=8)
  30. text10.place(x=115,y=280)
  31. text11 = tk.Label(win,text="奖品11:\n放假",bg=bg,height=3,width=8)
  32. text11.place(x=30,y=285)
  33. text12 = tk.Label(win,text="奖品12:\n搬家去云南",bg=bg,height=3,width=8)
  34. text12.place(x=30,y=215)
  35. text13 = tk.Label(win,text="奖品13:\n高考加分",bg=bg,height=3,width=8)
  36. text13.place(x=30,y=150)
  37. text14 = tk.Label(win,text="奖品14:\n海贼王",bg=bg,height=3,width=8)
  38. text14.place(x=30,y=85)
  39. text_list = [text1,text2,text3,text4,text5,text6,text7,text8,text9,text10,text11,text12,text13,text14]
  40. def menu():
  41. tkbox.showinfo("作者", "李狗蛋")
  42. mainmenu = tk.Menu(win)
  43. filemenu = tk.Menu(mainmenu,tearoff=False)
  44. mainmenu.add_cascade (label="操作",menu=filemenu)
  45. filemenu.add_command (label="作者",command=menu)
  46. filemenu.add_command (label="退出",command=win.quit)
  47. win.config (menu=mainmenu)
  48. def end_code():
  49. global vary_sleep
  50. vary_sleep = False
  51. def rounds():
  52. global sleep,vary_sleep
  53. if sleep==True:
  54. x = 0
  55. while True:
  56. if vary_sleep==False:
  57. value = text_list[x-1]['text']
  58. tkbox.showinfo("感谢您的关注","恭喜获得:{}".format(value))
  59. tkbox.showinfo("如果对您有帮助", "请前往某某地 领取您的奖品!!!")
  60. return
  61. else:
  62. time.sleep(0.2)
  63. for i in text_list:
  64. i['bg'] = "white"
  65. text_list[x]['bg'] = 'red'
  66. x += 1
  67. if x >= len(text_list):
  68. x = 0
  69. else:
  70. return
  71. def start():
  72. t = threading.Thread(target=rounds)
  73. t.start()
  74. start_button = tk.Button(win,text="开始",height=4,width=10,command=start)
  75. start_button.place(x=105,y=125)
  76. start_button = tk.Button(win,text="结束",height=4,width=10,command=end_code)
  77. start_button.place(x=195,y=125)
  78. win.mainloop()

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/198930
推荐阅读
相关标签
  

闽ICP备14008679号