欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python實(shí)現(xiàn)大轉(zhuǎn)盤抽獎(jiǎng)效果

 更新時(shí)間:2021年06月06日 12:28:12   作者:max_ez  
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)大轉(zhuǎn)盤抽獎(jiǎng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了python實(shí)現(xiàn)大轉(zhuǎn)盤抽獎(jiǎng)的具體代碼,供大家參考,具體內(nèi)容如下

選擇轉(zhuǎn)盤中的某一個(gè)方框,來(lái)進(jìn)行抽獎(jiǎng)

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信號(hào)
#存儲(chǔ)停止id------用于進(jìn)行stop后的重新啟動(dòng)
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ù)值對(duì)應(yīng)的組件變色
  fruitlists[i]['bg'] = 'red'
  #變量+1
  i += 1
  print('當(dāng)前i為',i) #當(dāng)前i,用來(lá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í) ,直接跳過(guò)
  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()

效果圖:

就是上圖這個(gè)界面了:

start 開始按鈕

stop 結(jié)束按鈕

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • TensorFlow學(xué)習(xí)之分布式的TensorFlow運(yùn)行環(huán)境

    TensorFlow學(xué)習(xí)之分布式的TensorFlow運(yùn)行環(huán)境

    這篇文章主要了TensorFlow學(xué)習(xí)之分布式的TensorFlow運(yùn)行環(huán)境的相關(guān)知識(shí),本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-02-02
  • Python調(diào)用百度api實(shí)現(xiàn)語(yǔ)音識(shí)別詳解

    Python調(diào)用百度api實(shí)現(xiàn)語(yǔ)音識(shí)別詳解

    這篇文章主要介紹了Python通過(guò)調(diào)用百度api實(shí)現(xiàn)語(yǔ)音識(shí)別,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧
    2021-12-12
  • python中stdout輸出不緩存的設(shè)置方法

    python中stdout輸出不緩存的設(shè)置方法

    這篇文章主要介紹了python中stdout輸出不緩存的設(shè)置方法,這個(gè)方法只在比較特殊的環(huán)境中使用,需要的朋友可以參考下
    2014-05-05
  • 詳解在Python中以絕對(duì)路徑或者相對(duì)路徑導(dǎo)入文件的方法

    詳解在Python中以絕對(duì)路徑或者相對(duì)路徑導(dǎo)入文件的方法

    這篇文章主要介紹了詳解在Python中以絕對(duì)路徑或者相對(duì)路徑導(dǎo)入文件的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • python爬蟲進(jìn)階之協(xié)程詳解

    python爬蟲進(jìn)階之協(xié)程詳解

    這篇文章主要介紹了python爬蟲進(jìn)階之協(xié)程詳解,coroutine中文翻譯叫協(xié)程,在 Python 中昌指代為協(xié)程對(duì)象類型,可以將協(xié)程對(duì)象注冊(cè)到時(shí)間循環(huán)中被調(diào)用,需要的朋友可以參考下
    2023-08-08
  • Django高級(jí)編程之自定義Field實(shí)現(xiàn)多語(yǔ)言

    Django高級(jí)編程之自定義Field實(shí)現(xiàn)多語(yǔ)言

    這篇文章主要介紹了Django高級(jí)編程之自定義Field實(shí)現(xiàn)多語(yǔ)言,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • PySide和PyQt加載ui文件的兩種方法

    PySide和PyQt加載ui文件的兩種方法

    這篇文章主要為大家詳細(xì)介紹了PySide和PyQt加載ui文件的兩種方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-02-02
  • Python list列表中刪除多個(gè)重復(fù)元素操作示例

    Python list列表中刪除多個(gè)重復(fù)元素操作示例

    這篇文章主要介紹了Python list列表中刪除多個(gè)重復(fù)元素操作,結(jié)合實(shí)例形式分析了Python刪除list列表重復(fù)元素的相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下
    2019-02-02
  • python使用PyV8執(zhí)行javascript代碼示例分享

    python使用PyV8執(zhí)行javascript代碼示例分享

    這篇文章主要介紹了python使用PyV8執(zhí)行javascript的小示例,大家參考使用吧
    2013-12-12
  • Java基礎(chǔ)技術(shù)之反射詳解

    Java基礎(chǔ)技術(shù)之反射詳解

    這篇文章主要介紹了Java基礎(chǔ)技術(shù)之反射詳解,反射就是把Java類中的各個(gè)部分,映射成一個(gè)個(gè)的Java對(duì)象,拿到這些對(duì)象后可以做一些事情,需要的朋友可以參考下
    2023-07-07

最新評(píng)論