试图生成一个随机团队,然后将其从选择列表中删除,希望添加“没有团队”的显示,但需要一些帮助
from tkinter import *
import random
def teams():
words_list = [ Atlanta Hawks ,
Boston Celtics ,
Brooklyn Nets ,
Charlotte Hornets ,
Chicago Bulls ,
Cleveland Cavaliers ,
Dallas Mavericks ,
Denver Nuggets ,
Detroit Pistons ,
Golden State Warriors ,
Houston Rockets ,
Indiana Pacers ,
Los Angeles Clippers ,
Los Angeles Lakers ,
Memphis Grizzlies ,
Miami Heat ,
Milwaukee Bucks ,
Minnesota Timberwolves ,
New Orleans Pelicans ,
New York Knicks ,
Oklahoma City Thunder ,
Orlando Magic ,
Philadelphia 76ers ,
Phoenix Suns ,
Portland Trail Blazers ,
Sacramento Kings ,
San Antonio Spurs ,
Toronto Raptors ,
Utah Jazz ,
Washington Wizards ]
while words_list:
team = words_list.pop(random.randrange(len(words_list)))
label.config(text=team)
window = Tk()
icon = PhotoImage(file= IMG_0612.png )
window.iconphoto(True, icon)
button = Button(window, text= Click me!!! )
button.config(command=teams) # performs call back of function
button.config(font=( Ink Free , 20, bold ))
button.config(bg= #ff6200 )
button.config(fg= #fffb1f )
button.config(activebackground= #FF0000 )
button.config(activeforeground= #fffb1f )
image = PhotoImage(file= IMG_0612.png )
button.config(image=image)
button.config(compound= bottom )
label = Label(window)
label.config(font=( Monospace , 50))
label.pack()
button.pack()
window.mainloop()
当所有单词都被删除时,我正在排除崩溃,但列表只是随着按钮重复,表现得就像删除代码根本不存在一样。