抽奖小程序(python+tkinter)

学习Python的GUI编程,编写了一个随机抽取姓名的小程序,主要参考资料

http://www.10tiao.com/html/383/201703/2247484257/1.html

 

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)


students=['杨姐姐1','杨姐姐2','杨姐姐3','杨姐姐4','杨姐姐5','杨姐姐6']

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.1)


#开始按钮
def butStartClick():
    t=threading.Thread(target=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()

 

转载于:https://www.cnblogs.com/ronyjay/p/7151106.html

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值