zoukankan      html  css  js  c++  java
  • 显示一个抽奖程序

    import tkinter
    import random
    import threading
    import time

    import tkinter as tk
    from PIL import Image, ImageTk

    class App(tk.Frame):
    def __init__(self, master=None):
    super().__init__(master, width=400, height=300)
    self.pack()
    self.pilImage = Image.open("dog.png")
    self.tkImage = ImageTk.PhotoImage(image=self.pilImage)
    self.label = tk.Label(self, image=self.tkImage)
    self.label.pack()

    def processEvent(self, event):
    pass

    # 初始化窗口
    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 = ['张三', '李四', '王五', '赵六', '黄七', '马八']

    i=0

    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)

    if not root.flag:
    print(i)
    app = App(root)


    # 开始按钮
    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()
  • 相关阅读:
    Codeforces 1082 毛毛虫图构造&最大权闭合子图
    BZOJ 1003 最短路dp
    BZOJ 1002 生成树计数&高精度
    BZOJ 1001 平面图转对偶图
    BZOJ 世界树
    一般图极大团个数,最大团顶点数
    第十五届四川省省赛 SCU
    第十五届四川省省赛 SCU
    第十五届四川省省赛 SCU
    BZOJ4671异或图
  • 原文地址:https://www.cnblogs.com/littlehb/p/9043292.html
Copyright © 2011-2022 走看看