Python 选择转盘中某一个方框,来进行抽奖示例

Python 选择转盘中某一个方框,来进行抽奖示例,第1张

概述Python 选择转盘中某一个方框,来进行抽奖示例 感兴趣Python 选择转盘中某一个方框,来进行抽奖示例的小伙伴,下面一起跟随内存溢出 jb51.cc的小编来看看吧。<br>
#  *** 网 (jb51.cc) ***import tkinter#导入线程模块import threadingimport time  #导入代码的sleep 代码休眠 root = tkinter.Tk()root.Title('大转盘')root.minsize(300,300) #摆放按钮btn1 = tkinter.button(root,text = '樱桃',bg = 'red')btn1.place(x = 20,y = 20,wIDth = 50,height = 50) btn2 = tkinter.button(root,text = '香蕉',bg = 'white')btn2.place(x = 90,height = 50) btn3 = tkinter.button(root,text = '苹果',bg = 'white')btn3.place(x = 160,height = 50) btn4 = tkinter.button(root,text = '西瓜',bg = 'white')btn4.place(x = 230,height = 50) btn5 = tkinter.button(root,text = '鸭梨',bg = 'white')btn5.place(x = 230,y = 90,height = 50) btn6 = tkinter.button(root,text = '榴莲',bg = 'white')btn6.place(x = 230,y = 160,height = 50) btn7 = tkinter.button(root,text = '柚子',bg = 'white')btn7.place(x = 230,y = 230,height = 50) btn8 = tkinter.button(root,text = '葡萄',bg = 'white')btn8.place(x = 160,height = 50) btn9 = tkinter.button(root,text = '草莓',bg = 'white')btn9.place(x = 90,height = 50) btn10 = tkinter.button(root,text = '芒果',bg = 'white')btn10.place(x = 20,height = 50) btn11 = tkinter.button(root,text = '荔枝',bg = 'white')btn11.place(x = 20,height = 50) btn12 = tkinter.button(root,text = '甘蔗',bg = 'white')btn12.place(x = 20,height = 50) #将所有选项组成列表fruit@R_404_6818@s = [btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btn10,btn11,btn12] #是否开启循环的标志isloop = False#是否停止标志stopsign=False    #是否接收到 stop信号#存储停止ID------用于进行stop后的重新启动stopID=Nonedef round():    global isloop    global stopID    #判断是否开始循环    if isloop == True:        return    i=1    if isinstance(stopID,int):        i=stopID    while True:        #延时 *** 作        time.sleep(0.2)        #将所有的组件背景变为白色        for x in fruit@R_404_6818@s:            x['bg'] = 'white'        #将当前数值对应的组件变色        fruit@R_404_6818@s[i]['bg'] = 'red'        #变量+1        i += 1        print('当前i为',i) #当前i,用来追踪当前位置        #如果i大于最大索引直接归零        if i >= len(fruit@R_404_6818@s):            i = 0        if stopsign == True:#当停止标志 为真时            isloop=False            stopID =i#赋值stopID            breakdef stop1():    global stopsign     if stopsign ==True:#当多接收stop1()函数时 ,直接跳过        return    stopsign=True#建立一个新线程的函数def newtask():    global isloop    global stopsign    #建立线程    stopsign=False    #print(stopsign)  #打印 点击开始时的stopsign    t = threading.Thread(target = round)    #开启线程运行    t.start()    # 设置循环开始标志    isloop = True     #开始按钮btn_start = tkinter.button(root,text = 'start',command = newtask)btn_start.place(x = 90,y = 125,height = 50) #停止按钮btn_stop = tkinter.button(root,text = 'stop',command=stop1)btn_stop.place(x = 160,height = 50) root.mainloop()#   *** 网 (jb51.cc) ***
  总结

以上是内存溢出为你收集整理的Python 选择转盘中某一个方框,来进行抽奖示例全部内容,希望文章能够帮你解决Python 选择转盘中某一个方框,来进行抽奖示例所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1199886.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存