python实现 抽奖/点名/发言系统

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

root = tk.Tk()      #初始化Tk() 建立一个窗口
root.title('班会提问系统') # 设置标题
root.minsize(800, 700)

# photo = tk.PhotoImage(file="1.png")  # file:图片路径
# imgLabel = tk.Label(root, image=photo)  # 把图片整合到标签类中
# imgLabel.pack(side=tk.RIGHT)  # 右对齐
width = 150   # 方块宽度
height = 100   # 方块高度
s=30  # 字体大小

label1 = tk.Label(root, text='dxx', bg='yellow', font=('Arial', s))
label1.place(x=10, y=300, width=width, height=height)

label2 = tk.Label(root, text='ssy', bg='yellow', font=('Arial', s))
label2.place(x=10, y=10, width=width, height=height)

label3 = tk.Label(root, text='wly', bg='yellow', font=('Arial', s))
label3.place(x=200, y=10, width=width, height=height)

label4 = tk.Label(root, text='wcw', bg='yellow', font=('Arial', s))
label4.place(x=400, y=10, width=width, height=height)

label5 = tk.Label(root, text='lyq', bg='yellow', font=('Arial', s))
label5.place(x=600, y=10, width=width, height=height)

label6 = tk.Label(root, text='cyx', bg='yellow', font=('Arial', s))
label6.place(x=800, y=10, width=width, height=height)

label7 = tk.Label(root, text='zjh', bg='yellow', font=('Arial',s))
label7.place(x=200, y=300, width=width, height=height)

label8 = tk.Label(root, text='zlx', bg='yellow', font=('Arial', s))
label8.place(x=400, y=300, width=width, height=height)

label9 = tk.Label(root, text='lwq', bg='yellow', font=('Arial', s))
label9.place(x=600, y=300, width=width, height=height)

label10 = tk.Label(root, text='kbc', bg='yellow', font=('Arial', s))
label10.place(x=800, y=300, width=width, height=height)

# label11 = tk.Label(root, text='最终解释权归【我】所有', bg='white', font=('Arial', 20))
# label11.place(x=650, y=400, width=700, height=100)

# 将所有抽奖选项添加到列表
things = [label1, label2, label3, label4, label5, label6, label7, label8, label9, label10]
# 获取列表的最大索引值
maxvalue = len(things) - 1

# 设置起始值为随机整数
starts = random.randint(0, 10)
# 是否停止标志
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.03)

        # 在所有抽奖选项中循环滚动
        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” 字体大小“30”   回调函数command 为【滚动函数】
btn1 = tk.Button(root, text='RUN', bg='lightSkyBlue', font=('Arial', 30), command=round)
#设置按键坐标
btn1.place(x=300, y=450, width=150, height=150)
# 设置停止按键      背景文本为“RUN”  底色为“红色”    字体“Arial” 字体大小“50”   回调函数command 为【停止函数】
btn2 = tk.Button(root, text='STOP', bg='red', font=('Arial', 30), command=stops)
#设置按键坐标
btn2.place(x=600, y=450, width=150, height=150)

# 循环,时刻刷新窗口
root.mainloop()
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Weiyaner

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值