資源簡介
使用Tkinter —— Python 的標準 GUI 庫,
實現簡易幸運轉盤式抽獎界面。

代碼片段和文件信息
import?time
import?threading
from?PIL?import?Image
import?tkinter?as?tk??#?導入?tk庫?模塊
import?random?????????#?導入?隨機庫?模塊
root?=?tk.Tk()??????#初始化Tk()?建立一個窗口
root.title(‘集大電協(xié)簡易抽獎‘)?#?設置標題
root.minsize(1000?700)
photo?=?tk.PhotoImage(file=“ETA.png“)??#?file:圖片路徑
imgLabel?=?tk.Label(root?image=photo)??#?把圖片整合到標簽類中
imgLabel.pack(side=tk.RIGHT)??#?右對齊
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=‘簡易四軸‘?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=‘再來一次‘?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=‘轉盤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=‘再來一次‘?bg=‘yellow‘?font=(‘Arial‘?50))
label10.place(x=390?y=600?width=390?height=250)
label11?=?tk.Label(root?text=‘最終解釋權歸【集美大學學·生電子技術協(xié)會】所有‘?bg=‘white‘?font=(‘Arial‘?20))
label11.place(x=1250?y=900?width=700?height=100)
#?將所有抽獎選項添加到列表
things?=?[label1?label2?label3?label4?label5?label6?label7?label8?label9?label10]
#?獲取列表的最大索引值
maxvalue?=?len(things)?-?1
#?設置起始值為隨機整數
starts?=?random.randint(0?6)
#?是否停止標志
notround?=?False
#?定義滾動函數
def?round():
????t?=?threading.Thread(target=startup)?#啟動start
????t.start()
#?定義開始函數
def?startup():
????global?starts
????global?notround
????while?True:
????????#?檢測停止按鈕是否被按下
????????if?notround?==?True:
????????????notround?=?False
????????????return?starts
????????#?程序延時
????????time.sleep(0.017)
????????#?在所有抽獎選項中循環(huán)滾動
????????for?i?in?things:
????????????i[‘bg‘]?=?‘lightSkyBlue‘?#開始時?底色變成天藍
????????things[starts][‘bg‘]?=?‘red‘?#滾動框為?紅色
????????starts?+=?1
????????if?starts?>?maxvalue:
????????????starts?=?0
#?定義停止函數
def?stops():
????global?notround?#?notround?為全局變量
????global?starts
????notround?=?True??#停止標志位
????if?starts?==?1:??#?如果抽中“簡易四軸”就跳轉為“謝謝惠顧”【奸商^_^】
????????starts?=?2
#?設置啟動按鍵??????背景文本為“RUN”??底色為“天藍”????字體“Arial”?字體大小“50”???回調函數command?為【滾動】
btn1?=?tk.Button(root?text=‘RUN‘?bg=‘lightSkyBlue‘?font=(‘Arial‘?50)?command=round)
#設置按鍵坐標
btn1.place(x=800?y=850?width=200?height=200)
#?設置停止按鍵??????背景文本為“RUN”??底色為“紅色”????字體“Arial”?字體大小“50”?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????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
- 上一篇:利用KMeans算法對點云數據進行分類
- 下一篇:opencv_tensorflow
評論
共有 條評論