python實現(xiàn)大轉(zhuǎn)盤抽獎效果
更新時間:2021年06月06日 12:28:12 作者:max_ez
這篇文章主要為大家詳細介紹了python實現(xiàn)大轉(zhuǎn)盤抽獎效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了python實現(xiàn)大轉(zhuǎn)盤抽獎的具體代碼,供大家參考,具體內(nèi)容如下
選擇轉(zhuǎn)盤中的某一個方框,來進行抽獎
import tkinter #導入線程模塊 import threading import time #導入代碼的sleep 代碼休眠 root = tkinter.Tk() root.title('大轉(zhuǎn)盤') 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] #是否開啟循環(huán)的標志 isloop = False #是否停止標志 stopsign=False #是否接收到 stop信號 #存儲停止id------用于進行stop后的重新啟動 stopid=None def round(): global isloop global stopid #判斷是否開始循環(huán) if isloop == True: return i=1 if isinstance(stopid,int): i=stopid while True: #延時操作 time.sleep(0.2) #將所有的組件背景變?yōu)榘咨? for x in fruitlists: x['bg'] = 'white' #將當前數(shù)值對應的組件變色 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 break def stop1(): global stopsign if stopsign ==True:#當多接收stop1()函數(shù)時 ,直接跳過 return stopsign=True #建立一個新線程的函數(shù) def newtask(): global isloop global stopsign #建立線程 stopsign=False #print(stopsign) #打印 點擊開始時的stopsign t = threading.Thread(target = round) #開啟線程運行 t.start() # 設置循環(huán)開始標志 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()
效果圖:
就是上圖這個界面了:
start 開始按鈕
stop 結束按鈕
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
TensorFlow學習之分布式的TensorFlow運行環(huán)境
這篇文章主要了TensorFlow學習之分布式的TensorFlow運行環(huán)境的相關知識,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2020-02-02Python調(diào)用百度api實現(xiàn)語音識別詳解
這篇文章主要介紹了Python通過調(diào)用百度api實現(xiàn)語音識別,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習吧2021-12-12Django高級編程之自定義Field實現(xiàn)多語言
這篇文章主要介紹了Django高級編程之自定義Field實現(xiàn)多語言,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-07-07python使用PyV8執(zhí)行javascript代碼示例分享
這篇文章主要介紹了python使用PyV8執(zhí)行javascript的小示例,大家參考使用吧2013-12-12