|
1威望
大家好,我刚开始学python,想做一个抽奖程序,源代码如下,如果我要在框架内除了“开始”“结束”外在加上3个按钮(一等奖,二等奖,三等奖)点击1等奖按钮就只出现一个随机滚动的人员名单,2等奖按钮出现2个滚动的滚动栏,依次类推。
这是我在网上找的代码,现在1,2,3等奖的按钮跟开始功能键一样,求大神教一下怎么样一个按钮显示不同等人数。一个人只能中奖一次,并且能输出中奖人员名单。
import tkinterimport randomimport threadingimport timeimport 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 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 = FalsebutStop = tkinter.Button(root, text='停止', command=btnStopClick)butStop.place(x=410, y=30, width=80, height=20)# 启动主程序root.mainloop()
|
-
|