【发布时间】:2019-12-28 11:37:35
【问题描述】:
我正在使用 Python 和 tkinter 构建一个多项选择游戏,我需要能够随机播放 GUI 上的按钮,以便包含正确答案的按钮的位置发生变化。到目前为止,我已经编写了这段代码,但似乎相同的 rely 值经常取自 y_list 多次导致按钮相互隐藏。如何确保每个rely 值只取一次?
y_list=[0.2,0.4,0.6,0.8]
def randy():
xan = random.choice(y_list)
return xan
y_list.remove(xan)
wordLabel = Label(newWindow, text=all_words_list[randWord])
wordLabel.place(relx=0.49, rely=0.1)
choice1=Button(newWindow, text=all_definitions_list[randDefinition], height=5, width=20)
choice1.place(relx=0.5,rely=randy(), anchor=N)
choice2=Button(newWindow, text="gangsta", height=5, width=20)
choice2.place(relx=0.5, rely=randy(), anchor=N)
choice3=Button(newWindow, text="gangsta", height=5, width=20)
choice3.place(relx=0.5, rely=randy(), anchor=N)
choice4=Button(newWindow, text="gangsta", height=5, width=20)
choice4.place(relx=0.5, rely=randy(), anchor=N)
【问题讨论】:
标签: python tkinter random shuffle