您好,登錄后才能下訂單哦!
本文章向大家介紹使用python編寫一個(gè)大轉(zhuǎn)盤抽獎(jiǎng)效果,主要包括使用python編寫一個(gè)大轉(zhuǎn)盤抽獎(jiǎng)效果的使用實(shí)例、應(yīng)用技巧、基本知識點(diǎn)總結(jié)和需要注意事項(xiàng),具有一定的參考價(jià)值,需要的朋友可以參考一下。
Python是一種編程語言,內(nèi)置了許多有效的工具,Python幾乎無所不能,該語言通俗易懂、容易入門、功能強(qiáng)大,在許多領(lǐng)域中都有廣泛的應(yīng)用,例如最熱門的大數(shù)據(jù)分析,人工智能,Web開發(fā)等。
具體內(nèi)容如下
import tkinter #導(dǎo)入線程模塊 import threading import time #導(dǎo)入代碼的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) #將所有選項(xiàng)組成列表 fruitlists = [btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btn10,btn11,btn12] #是否開啟循環(huán)的標(biāo)志 isloop = False #是否停止標(biāo)志 stopsign=False #是否接收到 stop信號 #存儲停止id------用于進(jìn)行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: #延時(shí)操作 time.sleep(0.2) #將所有的組件背景變?yōu)榘咨? for x in fruitlists: x['bg'] = 'white' #將當(dāng)前數(shù)值對應(yīng)的組件變色 fruitlists[i]['bg'] = 'red' #變量+1 i += 1 print('當(dāng)前i為',i) #當(dāng)前i,用來追蹤當(dāng)前位置 #如果i大于最大索引直接歸零 if i >= len(fruitlists): i = 0 if stopsign == True:#當(dāng)停止標(biāo)志 為真時(shí) isloop=False stopid =i#賦值stopid break def stop1(): global stopsign if stopsign ==True:#當(dāng)多接收stop1()函數(shù)時(shí) ,直接跳過 return stopsign=True #建立一個(gè)新線程的函數(shù) def newtask(): global isloop global stopsign #建立線程 stopsign=False #print(stopsign) #打印 點(diǎn)擊開始時(shí)的stopsign t = threading.Thread(target = round) #開啟線程運(yùn)行 t.start() # 設(shè)置循環(huán)開始標(biāo)志 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()
到此這篇關(guān)于使用python編寫一個(gè)大轉(zhuǎn)盤抽獎(jiǎng)效果的文章就介紹到這了,更多相關(guān)的內(nèi)容請搜索億速云以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持億速云!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。