-
大小: 86KB文件類(lèi)型: .rar金幣: 2下載: 0 次發(fā)布日期: 2021-06-02
- 語(yǔ)言: Python
- 標(biāo)簽: python??抽獎(jiǎng)界面??
資源簡(jiǎn)介
使用Tkinter —— Python 的標(biāo)準(zhǔn) GUI 庫(kù),
實(shí)現(xiàn)簡(jiǎn)易幸運(yùn)轉(zhuǎn)盤(pán)式抽獎(jiǎng)界面。

代碼片段和文件信息
import?time
import?threading
from?PIL?import?Image
import?tkinter?as?tk??#?導(dǎo)入?tk庫(kù)?模塊
import?random?????????#?導(dǎo)入?隨機(jī)庫(kù)?模塊
root?=?tk.Tk()??????#初始化Tk()?建立一個(gè)窗口
root.title(‘集大電協(xié)簡(jiǎn)易抽獎(jiǎng)‘)?#?設(shè)置標(biāo)題
root.minsize(1000?700)
photo?=?tk.PhotoImage(file=“ETA.png“)??#?file:圖片路徑
imgLabel?=?tk.Label(root?image=photo)??#?把圖片整合到標(biāo)簽類(lèi)中
imgLabel.pack(side=tk.RIGHT)??#?右對(duì)齊
label1?=?tk.Label(root?text=‘謝謝惠顧‘?bg=‘yellow‘?font=(‘Arial‘?50))
label1.place(x=0?y=600?width=390?height=250)
label2?=?tk.Label(root?text=‘簡(jiǎn)易四軸‘?bg=‘yellow‘?font=(‘Arial‘?50))
label2.place(x=0?y=10?width=390?height=250)
label3?=?tk.Label(root?text=‘謝謝惠顧‘?bg=‘yellow‘?font=(‘Arial‘?50))
label3.place(x=390?y=10?width=390?height=250)
label4?=?tk.Label(root?text=‘mini光立方‘?bg=‘yellow‘?font=(‘Arial‘?50))
label4.place(x=780?y=10?width=390?height=250)
label5?=?tk.Label(root?text=‘再來(lái)一次‘?bg=‘yellow‘?font=(‘Arial‘?50))
label5.place(x=1170?y=10?width=390?height=250)
label6?=?tk.Label(root?text=‘謝謝惠顧‘?bg=‘yellow‘?font=(‘Arial‘?50))
label6.place(x=1560?y=10?width=390?height=250)
label7?=?tk.Label(root?text=‘轉(zhuǎn)盤(pán)PCB‘?bg=‘yellow‘?font=(‘Arial‘?50))
label7.place(x=1560?y=600?width=390?height=250)
label8?=?tk.Label(root?text=‘謝謝惠顧‘?bg=‘yellow‘?font=(‘Arial‘?50))
label8.place(x=1170?y=600?width=390?height=250)
label9?=?tk.Label(root?text=‘51核心板‘?bg=‘yellow‘?font=(‘Arial‘?50))
label9.place(x=780?y=600?width=390?height=250)
label10?=?tk.Label(root?text=‘再來(lái)一次‘?bg=‘yellow‘?font=(‘Arial‘?50))
label10.place(x=390?y=600?width=390?height=250)
label11?=?tk.Label(root?text=‘最終解釋權(quán)歸【集美大學(xué)學(xué)·生電子技術(shù)協(xié)會(huì)】所有‘?bg=‘white‘?font=(‘Arial‘?20))
label11.place(x=1250?y=900?width=700?height=100)
#?將所有抽獎(jiǎng)選項(xiàng)添加到列表
things?=?[label1?label2?label3?label4?label5?label6?label7?label8?label9?label10]
#?獲取列表的最大索引值
maxvalue?=?len(things)?-?1
#?設(shè)置起始值為隨機(jī)整數(shù)
starts?=?random.randint(0?6)
#?是否停止標(biāo)志
notround?=?False
#?定義滾動(dòng)函數(shù)
def?round():
????t?=?threading.Thread(target=startup)?#啟動(dòng)start
????t.start()
#?定義開(kāi)始函數(shù)
def?startup():
????global?starts
????global?notround
????while?True:
????????#?檢測(cè)停止按鈕是否被按下
????????if?notround?==?True:
????????????notround?=?False
????????????return?starts
????????#?程序延時(shí)
????????time.sleep(0.017)
????????#?在所有抽獎(jiǎng)選項(xiàng)中循環(huán)滾動(dòng)
????????for?i?in?things:
????????????i[‘bg‘]?=?‘lightSkyBlue‘?#開(kāi)始時(shí)?底色變成天藍(lán)
????????things[starts][‘bg‘]?=?‘red‘?#滾動(dòng)框?yàn)?紅色
????????starts?+=?1
????????if?starts?>?maxvalue:
????????????starts?=?0
#?定義停止函數(shù)
def?stops():
????global?notround?#?notround?為全局變量
????global?starts
????notround?=?True??#停止標(biāo)志位
????if?starts?==?1:??#?如果抽中“簡(jiǎn)易四軸”就跳轉(zhuǎn)為“謝謝惠顧”【奸商^_^】
????????starts?=?2
#?設(shè)置啟動(dòng)按鍵??????背景文本為“RUN”??底色為“天藍(lán)”????字體“Arial”?字體大小“50”???回調(diào)函數(shù)command?為【滾動(dòng)】
btn1?=?tk.Button(root?text=‘RUN‘?bg=‘lightSkyBlue‘?font=(‘Arial‘?50)?command=round)
#設(shè)置按鍵坐標(biāo)
btn1.place(x=800?y=850?width=200?height=200)
#?設(shè)置停止按鍵??????背景文本為“RUN”??底色為“紅色”????字體“Arial”?字體大小“50”?
?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????文件?????110235??2018-09-09?12:37??ETA.png
?????文件???????3879??2019-01-22?18:11??ETA.py
?????文件?????????37??2019-01-22?18:19??readme.txt
-----------?---------??----------?-----??----
???????????????114151????????????????????3
評(píng)論
共有 條評(píng)論