我正在尝试使用python tkinter创建一个匹配国家和首都的游戏 . 我现在困惑的是当我使用random.choice时 . 在我使用random.choice之后,我希望得到一个与彼此匹配的键和值 . 请帮助
from tkinter import*
import random
window = Tk()
question = 1
nations_capitals = {
'South Korea' : 'Seoul',
'Japan' :'Tokyo',
'China': 'Beijing',
'Thailand':'Bangkok'
}
nations_flags= {
'South Korea' : 'Korea.gif',
'Japan' : 'Japan.gif',
'China' : 'China.gif',
'Thailnad' : 'Thailand.gif'
}
wall = PhotoImage(file = "globe.gif")
wall_label = Label(image = wall)
wall_label.place(x=0,y=0)
window.title("Capital Game")
window.geometry("800x600")
window.resizable(False,False)
def Start_Game():
choice=random.choice(nations_flags(items))
window.destroy()
window1=Tk()
window1.title("Capital")
window1.geometry("800x600")
window1.resizable(False,False)
window1.config(bg="skyblue")
T = Text(window1, height=2, width = 30)
T.pack()
T.insert(INSERT,list(nations_flags.keys[choice]))
flag = PhotoImage(file = list(nations_flags.values[choice]))
flag_label = Label(image = flag)
flag_label.image = flag
flag_label.place(x=210,y=120)
button1 = Button(window1, text=random.choice(list(nations_capitals.values())), bg = "white", fg = "skyblue", command = click)
button2 = Button(window1, text=random.choice(list(nations_capitals.values())), bg = "white", fg = "skyblue", command = click)
button3 = Button(window1, text=random.choice(list(nations_capitals.values())), bg = "white", fg = "skyblue", command = click)
button4 = Button(window1, text=random.choice(list(nations_capitals.values())), bg = "white", fg = "skyblue", command = click)
button1.place(x=200, y =400)
button2.place(x=550, y =400)
button3.place(x=200, y =500)
button4.place(x=550, y =500)
button = Button(window, text="GameStart!", bg = "skyblue", fg = "white", command = Start_Game)
button.place(x=375, y =500)
window.mainloop()