我正在尝试修改我的抽认卡 python 脚本。它工作正常,但我正在尝试做的是修改随机函数,以便单个问题(及其答案)不会被选择两次。列表完成后,脚本不应继续选择问题。我还需要添加一个按钮,让我可以返回到以前的选择。
有什么建议吗?
from tkinter import *
from tkinter import ttk
from random import randint
root = Tk()
root.title('Domande')
root.geometry("850x400")
root.resizable(True, True)
words = [
(("Stadio Olimpico"), ("ROMA")),
(("Stadio Artemio Franchi"), ("FIORENTINA")),
(("Stadio Armando Picchi"), ("LIVORNO")),
(("Stadio Luigi Ferraris"), ("SAMPDORIA"))
(("Stadio Arechi"), ("SALERNITANA"))
]
# get a count of our wods list
count = len(words)
def next():
global hinter, hint_count
#Clear screen
answer_label.config(text="")
label.config(text="")
hint_label.config(text="")
#Reset Hint stuff
hinter = ""
hint_count = 0
#Create random selection
global random_domande
random_domande = randint(0, count-1)
#Update label with Domande
domande.config(text=words[random_domande][0])
#Keep track of the hint
hinter = ""
hint_count = 0
def hint():
global hint_count
global hinter
if hint_count < len(words[random_domande][1]):
hinter = hinter + words[random_domande][1][hint_count]
hint_label.config(text=hinter)
hint_count +=1
#Define function to hide the widget
def hide_widget(widget):
widget.pack_forget()
widget.config(text=words[random_domande][1])
#Define a function to show the widget
def show_widget(widget):
widget.pack()
widget.config(text=words[random_domande][1])
#Labels
domande = Label(root, text="", font=("Times", 14))
domande.pack(side=TOP)
#Create an Label Widget
label = Label(root, text="", font=("Times", 14))
label.pack()
#Create Buttons
button_frame = Frame(root)
button_frame.pack()
hint_button = Button(button_frame, text="Hint", command=hint)
hint_button.pack()
button_show = Button(root, text= "Show", command= lambda:show_widget(label))
button_show.pack()
#Create a button Widget
button_hide = Button(root, text= "Hide", command=lambda:hide_widget(label))
button_hide.pack()
next_button = Button(button_frame, text="Next", command=next)
next_button.pack()
#Create Hint Label
hint_label = Label(root, text="")
hint_label.pack()
answer_label = Label(root, text="", font=("Times", 14))
answer_label.pack(side=BOTTOM)
#Run next function when the program starts
next()
root.mainloop()