基于Python实现商场抽奖小系统

作者:顾木子吖 时间:2021-07-01 14:46:14 

导语

嘿!下午好,木子来上新啦~

期待今天的内容嘛?挠头.jpg 日常等更新的小可爱们我来了。看看给大家带来了什么好东西

💦💦💦💦💦💦💦💦💦💦💦💦我是华丽的分隔符💦💦💦💦💦💦💦💦💦💦💦💦💦

今天早上出门了一趟,话说长沙的天气用一个字形容就是:”热“、二个字形容:”真热“、三个字形容:”热死人“,据说这几天的温度快达到40°了。大家记得做好防晒哦~

基于Python实现商场抽奖小系统

一出门就感受到了太阳的拥抱,泪流满面的做完事情之后跑到商场喝了杯茶颜,然后逛着街吹着免费的空调,巴适的很啊!逛商场的时候看到了转盘抽奖活动,简直不要太适合我这种想买买买(白嫖)的人。嘿嘿,嘛~说了这么多的(废话)话,揭开谜底吧!我想你们等不及了

今天的主题就是给大家制作一款商场抽奖小系统,保证你喜欢,学了不后悔系列~

基于Python实现商场抽奖小系统

一、运行环境

小编使用的环境:Python3、Pycharm社区版、Tkinter、PIL模块部分自带就不一一 展示啦。

模块安装:pip install -i https://pypi.douban.com/simple/+模块名

二、素材(图片等)

界面图片的话可以自己准备,这里不展示,想换什么背景可以自己随便找一张图就可哈。

但是要注意背景的大小尺寸问题哈。

基于Python实现商场抽奖小系统

三、代码展示

基本上每行代码都有注释的,这款代码写的挺简单的,有点儿小基础的可以看的懂哈!

如没基础小白的话可以找我先拿一些简单的视频,教你从0开始学习吧!

import time
import threading
from PIL import Image
import tkinter as tk  # 导入 tk库 模块
import random         # 导入 随机库 模块

root = tk.Tk()      #初始化Tk() 建立一个窗口
root.title('简易商场抽奖系统-顾木子吖') # 设置标题
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优惠券', 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优惠券', 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)

# 在所有抽奖选项中循环滚动
       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)界面效果  

这个程序界面比较大,截图之后科能看的不是很清楚,大家可以自己运行看的清楚些。

基于Python实现商场抽奖小系统

2)RUN运行

鼠标点击RUN运行按住STOP停止,随机抽奖的哈。我运气还是不错的小汽车能带回家,哈哈

基于Python实现商场抽奖小系统

这里没有视频展示,都是随便截图看下效果的哈,没有那么好~

运行起来是一直再轮流随机闪动的哈。

来源:https://blog.csdn.net/weixin_55822277/article/details/125895965

标签:Python,商场,抽奖,系统
0
投稿

猜你喜欢

  • python实现通过pil模块对图片格式进行转换的方法

    2021-03-06 01:55:54
  • 一个非常有代表性的javascript简易拖动类

    2009-05-25 12:44:00
  • WEB2.0网页制作标准教程(7)CSS学习入门

    2007-12-13 13:12:00
  • Python之requests的使用(二)

    2021-10-30 16:44:51
  • Python脚本实现格式化css文件

    2023-01-09 19:00:37
  • python中的bool数组取反案例

    2023-04-12 07:33:15
  • Discuz7 的提示效果如何实现

    2010-01-13 13:10:00
  • Flask框架运用Ajax实现数据交互的示例代码

    2023-11-19 19:15:19
  • Python标准库学习之psutil内存详解

    2023-09-14 21:33:35
  • 浅谈使用Python变量时要避免的3个错误

    2022-06-20 21:07:07
  • Django如何简单快速实现PUT、DELETE方法

    2021-04-14 17:53:07
  • sqlserver清空service broker中的队列的语句分享

    2011-09-30 11:33:35
  • python中的标准库html

    2022-01-09 22:04:25
  • Oracle 存储过程总结(一、基本应用)

    2009-07-07 10:21:00
  • 使用TensorFlow实现SVM

    2023-04-27 00:44:49
  • Python类绑定方法及非绑定方法实例解析

    2022-08-10 11:36:38
  • 形式追随内容?

    2010-03-07 15:55:00
  • css教程–十步学会用css建站(全)[翻译]

    2008-06-05 18:35:00
  • 如何利用Python实现简易的音频播放器

    2022-07-16 11:47:32
  • python如何将mat文件转为png

    2023-04-14 07:37:21
  • asp之家 网络编程 m.aspxhome.com