国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python實現大轉盤抽獎效果

2020-02-16 00:48:41
字體:
來源:轉載
供稿:網友

本文實例為大家分享了python實現大轉盤抽獎的具體代碼,供大家參考,具體內容如下

選擇轉盤中的某一個方框,來進行抽獎

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,y = 20,width = 50,height = 50) btn3 = tkinter.Button(root,text = '蘋果',bg = 'white')btn3.place(x = 160,y = 20,width = 50,height = 50) btn4 = tkinter.Button(root,text = '西瓜',bg = 'white')btn4.place(x = 230,y = 20,width = 50,height = 50) btn5 = tkinter.Button(root,text = '鴨梨',bg = 'white')btn5.place(x = 230,y = 90,width = 50,height = 50) btn6 = tkinter.Button(root,text = '榴蓮',bg = 'white')btn6.place(x = 230,y = 160,width = 50,height = 50) btn7 = tkinter.Button(root,text = '柚子',bg = 'white')btn7.place(x = 230,y = 230,width = 50,height = 50) btn8 = tkinter.Button(root,text = '葡萄',bg = 'white')btn8.place(x = 160,y = 230,width = 50,height = 50) btn9 = tkinter.Button(root,text = '草莓',bg = 'white')btn9.place(x = 90,y = 230,width = 50,height = 50) btn10 = tkinter.Button(root,text = '芒果',bg = 'white')btn10.place(x = 20,y = 230,width = 50,height = 50) btn11 = tkinter.Button(root,text = '荔枝',bg = 'white')btn11.place(x = 20,y = 160,width = 50,height = 50) btn12 = tkinter.Button(root,text = '甘蔗',bg = 'white')btn12.place(x = 20,y = 90,width = 50,height = 50) #將所有選項組成列表fruitlists = [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 fruitlists:   x['bg'] = 'white'  #將當前數值對應的組件變色  fruitlists[i]['bg'] = 'red'  #變量+1  i += 1  print('當前i為',i) #當前i,用來追蹤當前位置  #如果i大于最大索引直接歸零  if i >= len(fruitlists):   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,width = 50,height = 50) #停止按鈕btn_stop = tkinter.Button(root,text = 'stop',command=stop1)btn_stop.place(x = 160,y = 125,width = 50,height = 50) root.mainloop()            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 且末县| 通道| 若尔盖县| 四平市| 安徽省| 漠河县| 信宜市| 大兴区| 德令哈市| 新田县| 连江县| 芒康县| 如东县| 马山县| 安陆市| 潮安县| 屏山县| 青川县| 东兰县| 辽宁省| 察隅县| 利川市| 凤城市| 客服| 淮阳县| 鸡泽县| 固始县| 文安县| 福鼎市| 江安县| 巴塘县| 莎车县| 鄂托克旗| 阳曲县| 宾阳县| 东乌珠穆沁旗| 平阴县| 乐都县| 盐城市| 沐川县| 左贡县|