资源简介
使用Tkinter —— Python 的标准 GUI 库,
实现简易幸运转盘式抽奖界面。

代码片段和文件信息
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=‘简易四轴‘ 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=‘最终解释权归【集美大学学·生电子技术协会】所有‘ 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”
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 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
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论