前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >新手请教python抽奖程序

新手请教python抽奖程序

原创
作者头像
用户4033862
修改2018-11-27 14:38:19
2K0
修改2018-11-27 14:38:19
举报
文章被收录于专栏:python_lwx

大家好,我开始学python,想做一个抽奖程序,源代码如下,如果我要在框架内加上1等奖1个人 ,2等奖2个人,三等奖3个人 应该怎么样编写相关联的代码,就是点击1等奖按钮就只出现一个随机滚动的人员名单,2等奖按钮出现2个滚动的滚动栏,依次类推。

这是我在网上找的代码,1,2,3等奖的按钮跟开始功能一样,求大神教一下怎么样一个按钮显示不同等人数。最好能在这个人中奖后从列表中删除。

删除

代码如下:

代码语言:javascript
复制
import tkinter
import random
import threading
import time
import csv    #加载csv包便于读取csv文件
# 初始化窗口
root = tkinter.Tk()
root.title("上海克比年会抽奖名单")
root.geometry('500x500+400+200')
root.resizable(False, False)
root.flag = True
# 三个Lable标签
csv_file=open('c:/12.csv')    #打开csv文件
csv_reader_lines = csv.reader(csv_file)   #逐行读取csv文件
students = [ ]    #创建列表准备接收csv各行数据
for one_line in csv_reader_lines:
    students.append(one_line)  # 将读取的csv分行数据按行存入列表‘date’中
students.append(one_line)

def switch():
    root.flag = True
    while root.flag:
        i = random.randint(0, len(students) - 1)
        first['text'] = second['text']
        second['text'] = third['text']
        third['text'] = students[i]
        time.sleep(0.001)

first = tkinter.Label(root, text='', font=("宋体", 20, "normal"))
first.place(x=100, y=100, width=300, height=100)

second = tkinter.Label(root, text='', font=("宋体", 20, "normal"))
second['fg'] = 'red'
second.place(x=100, y=200, width=300, height=100)

third = tkinter.Label(root, text='', font=("宋体", 20, "normal"))
third.place(x=100, y=300, width=300, height=100)

# 开始按钮
def butStartClick():
    t = threading.Thread(target=switch)
    t.start()

#设置几个奖项
btnStart = tkinter.Button(root, text='开始', command=butStartClick)
btnStart.place(x=20, y=30, width=80, height=20)
one = tkinter.Button(root, text='一等奖', command=butStartClick)
one.place(x=110, y=30, width=80, height=20)
two = tkinter.Button(root, text='二等奖', command=butStartClick)
two.place(x=210, y=30, width=80, height=20)
three= tkinter.Button(root, text='三等奖', command=butStartClick)
three.place(x=310, y=30, width=80, height=20)

# 结束按钮
def btnStopClick():
    root.flag = False

butStop = tkinter.Button(root, text='停止', command=btnStopClick)
butStop.place(x=410, y=30, width=80, height=20)

# 启动主程序
root.mainloop()

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档