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