【发布时间】:2020-06-17 09:59:08
【问题描述】:
我的 tkinter 代码有问题。这就是我到目前为止得到的:
from tkinter import *
root = Tk()
def create_button():
liste = [['Name 1', 'Name 2', 'Name 3'], ['Name 4', 'Name 5', 'Name 6']]
#giving any button a diffrent command by changing the 'group'-parameter from the function show_player
for i in range(len(liste)):
Button_name = 'Group ' + str(i+1)
Button(root, text = Button_name, bg = 'white', command= lambda:[show_player(liste, i)]).pack()
def show_player(list1, group):
for name in list1[group]:
Label(root, text = name).pack()
create_button()
root.mainloop()
无论我按下哪个按钮,我都会得到名称“名称 4”、“名称 5”、“名称 6”,
但我希望第一个按钮创建名称为“名称 1”、“名称 2”、“名称 3”的标签
有谁知道为什么它不起作用?
【问题讨论】: