想弄一个抽奖的代码,从网上 copy 了大神的代码,现在想新添加一个功能就是→第一次和第二次点击结束显示都是 A,第三次是随机的。小白修改之后每次都是 A 了,求大佬帮助!!!

import tkinter
import random
import threading
import time


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

second = tkinter.Label(root,text='',font = ("宋体", 20,"normal"))
second['fg'] = 'red'
second.place(x=80,y=100,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']
        second['text'] = students[i]
        # third['text'] = students[i]
        time.sleep(0.05)



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
    count = 0
    while True:
        count = count + 1
        if count <= 2:
            second['text'] = "A"
            break



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


root.mainloop()


↙↙↙阅读原文可查看相关链接,并与作者交流