基于Python實現(xiàn)商場抽獎小系統(tǒng)
導語
嘿!下午好,木子來上新啦~
期待今天的內容嘛?撓頭.jpg 日常等更新的小可愛們我來了??纯唇o大家?guī)砹耸裁春脰|西
????????????????????????我是華麗的分隔符??????????????????????????
今天早上出門了一趟,話說長沙的天氣用一個字形容就是:”熱“、二個字形容:”真熱“、三個字形容:”熱死人“,據說這幾天的溫度快達到40°了。大家記得做好防曬哦~
一出門就感受到了太陽的擁抱,淚流滿面的做完事情之后跑到商場喝了杯茶顏,然后逛著街吹著免費的空調,巴適的很?。」渖虉龅臅r候看到了轉盤抽獎活動,簡直不要太適合我這種想買買買(白嫖)的人。嘿嘿,嘛~說了這么多的(廢話)話,揭開謎底吧!我想你們等不及了
今天的主題就是給大家制作一款商場抽獎小系統(tǒng),保證你喜歡,學了不后悔系列~
一、運行環(huán)境
小編使用的環(huán)境:Python3、Pycharm社區(qū)版、Tkinter、PIL模塊部分自帶就不一一 展示啦。
模塊安裝:pip install -i https://pypi.douban.com/simple/+模塊名
二、素材(圖片等)
界面圖片的話可以自己準備,這里不展示,想換什么背景可以自己隨便找一張圖就可哈。
但是要注意背景的大小尺寸問題哈。
三、代碼展示
基本上每行代碼都有注釋的,這款代碼寫的挺簡單的,有點兒小基礎的可以看的懂哈!
如沒基礎小白的話可以找我先拿一些簡單的視頻,教你從0開始學習吧!
import time import threading from PIL import Image import tkinter as tk # 導入 tk庫 模塊 import random # 導入 隨機庫 模塊 root = tk.Tk() #初始化Tk() 建立一個窗口 root.title('簡易商場抽獎系統(tǒng)-顧木子吖') # 設置標題 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='1000優(yōu)惠券', 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='蘋果手機', 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='5000優(yōu)惠券', 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='一臺小汽車', 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='顧木子吖', 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” 回調函數command 為【停止】 btn2 = tk.Button(root, text='STOP', bg='red', font=('Arial', 50), command=stops) #設置按鍵坐標 btn2.place(x=1000, y=850, width=200, height=200)
?四、效果展示
1)界面效果
這個程序界面比較大,截圖之后科能看的不是很清楚,大家可以自己運行看的清楚些。
2)RUN運行
鼠標點擊RUN運行按住STOP停止,隨機抽獎的哈。我運氣還是不錯的小汽車能帶回家,哈哈
這里沒有視頻展示,都是隨便截圖看下效果的哈,沒有那么好~
運行起來是一直再輪流隨機閃動的哈。
以上就是基于Python實現(xiàn)商場抽獎小系統(tǒng)的詳細內容,更多關于Python抽獎系統(tǒng)的資料請關注腳本之家其它相關文章!
相關文章
如何用python?GUI(tkinter)寫一個鬧鈴小程序(思路詳解)
這篇文章主要介紹了用python?GUI(tkinter)寫一個鬧鈴小程序思路詳解,涉及到tkinter一些函數控件,數據的類的封裝,本文通過實例代碼給大家介紹的非常詳細,需要的朋友可以參考下2021-12-12使用APScheduler3.0.1 實現(xiàn)定時任務的方法
今天小編就為大家分享一篇使用APScheduler3.0.1 實現(xiàn)定時任務的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-07-07python接口自動化之使用token傳入到header消息頭中
這篇文章主要介紹了python接口自動化之使用token傳入到header消息頭中問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-08-08Python基于TensorFlow接口實現(xiàn)深度學習神經網絡回歸
這篇文章主要為大家詳細介紹了如何基于Python語言中TensorFlow的tf.estimator接口,實現(xiàn)深度學習神經網絡回歸的具體方法,感興趣的可以了解一下2023-02-02