Python 如何在tkinter框中打印I的变量

Python 如何在tkinter框中打印I的变量,python,tkinter,Python,Tkinter,我正在构建一个随机获奖者生成器作为一个项目,从未使用过任何GUI工具 import random from random import shuffle from tkinter import * import time # Open the file and select a random winner names = open('names.txt').read().splitlines() winner = random.choice(names) #create the window

我正在构建一个随机获奖者生成器作为一个项目,从未使用过任何GUI工具

import random
from random import shuffle
from tkinter import *
import time

# Open the file and select a random winner
names = open('names.txt').read().splitlines()
winner = random.choice(names)

#create the window and basic setup
window = Tk()
window.title("Bergstrom Prize Winner Generator")
window.geometry('500x500')

#action to be performed when button clicked
def clicked():
    for x in range(1,3):
        for i in names:
            print(random.choice(names))
            time.sleep(0.25)

    print("and the winner is.....", winner, "!!!!")

btn1 = Button(window, text="Pick A Winner!", command=clicked)
btn1.grid(column=3, row=3)

window.mainloop()
我想在tkinter窗口中显示
I
的值,这样它会闪烁名称,然后最后显示获胜者的名称。我完全卡住了。请问有谁能提供建议吗

这应该行得通

from Tkinter import *

master = Tk()

w = Label(master, text = i)
w.pack()

mainloop()

此代码将列出names.txt文件中的所有名称,然后打印获胜者。你可以增加时间延迟

代码:

import random
from random import shuffle
from tkinter import *
import time

# Open the file and select a random winner
names = open('names.txt').read().splitlines()
winner = random.choice(names)

#create the window and basic setup
window = Tk()
window.title("Bergstrom Prize Winner Generator")
window.geometry('500x500')

#action to be performed when button clicked
def clicked():
    for ind, name in enumerate(names):
        # print names in the tkinter window
        names_label = Label(window)
        names_label.grid(row=int(ind)+1, column=0)
        names_label.config(text=name)
    time.sleep(0.25)
    names_label.config(text="and the winner is....." + winner + "!!!!")

btn1 = Button(window, text="Pick A Winner!", command=clicked)
btn1.grid(column=0, row=0)

window.mainloop()
输出:

import random
from random import shuffle
from tkinter import *
import time

# Open the file and select a random winner
names = open('names.txt').read().splitlines()
winner = random.choice(names)

#create the window and basic setup
window = Tk()
window.title("Bergstrom Prize Winner Generator")
window.geometry('500x500')

#action to be performed when button clicked
def clicked():
    for ind, name in enumerate(names):
        # print names in the tkinter window
        names_label = Label(window)
        names_label.grid(row=int(ind)+1, column=0)
        names_label.config(text=name)
    time.sleep(0.25)
    names_label.config(text="and the winner is....." + winner + "!!!!")

btn1 = Button(window, text="Pick A Winner!", command=clicked)
btn1.grid(column=0, row=0)

window.mainloop()

你好,非常感谢您的回复。这并不完全是我想要的,但这是朝着它迈出的一步。我所追求的是每次循环迭代时,打印I值,以便名称闪烁,而不是所有名称的列表