1

我已经阅读了类似主题的几个答案,但它们都与我的情况无关,我试图在标签上显示一个列表,每当按下按钮更新列表时,标签也应该更新,但它只会在submitbtn_name被点击。感谢任何帮助我对 Tkinter 很陌生。我的代码:

from tkinter import *

root = Tk()
root.title("Path Creator")
root.geometry('1680x1080')
root['background'] = '#aaaaaa'

list_of_paths_list = []
path_list = []


name = Entry(root, width=400)
name.insert(0, "Name")
name.pack()

def add_name():
    path_list.append(name.get())
    list_label = Label(root, text="path name:" + str(path_list))
    list_label.pack()

submitbtn_name = Button(root, text="submit name", command=add_name)
submitbtn_name.pack()

value1 = Entry(root, width=400)
value1.insert(0, "value1")
value1.pack()

distance1 = Entry(root, width=400)
distance1.insert(0, "distance1")
distance1.pack()

def submitbtn_value_dist():
    temp_list = []
    temp_list.append(value1.get())
    temp_list.append(distance1.get())
    path_list.append(tuple(temp_list))
    list_label = Label(root, text="current path: " + path_list)
    list_label.pack()

submitbtn_pathpart = Button(root, text="submit path part", )
submitbtn_pathpart.pack()
root.mainloop()


4

0 回答 0