2018-11-19抽奖小程序

-- encoding = 'utf-8' --

author = 'zhuoda'

import tkinter
import random
import threading
import time
''''
下一步要完成的是 从列表中去掉 已经 抽到过的数字, 停止时操作.
弹出窗口 恭喜对放框.
还没解决 输入的不是数字...提示一下...
'''

初始化窗口

root=tkinter.Tk()
root.title("随机名单")
root.geometry('500x500+400+200')
root.resizable(False,False)
root.flag = True

三个Lable标签

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

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

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

一个text 文本框

输入 抽奖的号码1到 N ,N为最大值

lable1 = tkinter.Label(root,text='请输入参与抽奖的人数:')
lable1.place(x=30, y=100, width=180, height=20)

text1 = tkinter.Entry()
text1.pack()

num = text1.get() #获取text1的内容

students = [i for i in range(1,50)]

text1.place(x=250, y=100, width=180, height=20)

studenst = []

students=[i for i in range(1,int(text1['text'] )+1)]

students=['小明1','小明2','小明3','小明4','小明5','小明6']

def get_num():
try:
if text1.get().isdigit: #如果输入的是数字 可以开始
return [i for i in range(1,int(text1.get())+1)] # 返回最大号码
else:
return False
except Exception as e:
print(e)

def switch():
if text1.get().isdigit(): #如果输入的是数字 可以开始
students = get_num() #获取 文本档中的内内容
root.flag = True
else:
root.flag = False
text1['text'] = '请输入数字'
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.1) # 数字刷新的时间

开始按钮

def butStartClick():
t=threading.Thread(target=switch) #运行switch 函数
t.start()

btnStart=tkinter.Button(root,text='开始',command=butStartClick)
btnStart.place(x=30, y=30, width=80, height=20)

结束按钮

def btnStopClick():
root.flag=False

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

启动主程序

root.mainloop()

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1、图形化界面设计的基本理解当前流行的计算机桌面应用程序大多数为图形化用户界面(Graphic User Inte...
    IIronMan阅读 259,705评论 15 244
  • Data Visualization with D3 D3: SVG中的jQurey 1. Add Documen...
    王策北阅读 857评论 0 2
  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 9,801评论 0 13
  • 残夕落幕处,聚散几陌陌。 怀这个字眼,总是充满温暖的,即是温暖,就容易产生依附而顿生惰性,怀可以向内弯曲的,有厚实...
    虫二略知秋阅读 335评论 0 0
  • 前段事件的重庆公交事件可谓是吸足了公众的注意力,先不说各种键盘侠打脸自己的事,事故终极原因是大巴车内女乘客和司机发...
    vivial阅读 2,002评论 0 0

友情链接更多精彩内容