1

I have read through several answers to similar topics but none of them are relevant to my situation, I am trying to display a list on a label and whenever the button is pressed to update the list the label should update as well but it only updates when submitbtn_name is clicked. Any help appreciated I am very new to Tkinter. My Code:

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()


Reacher42
  • 31
  • 3

1 Answers1

0

Using f-string format. Added command in submitbtn_pathpart

Snippet:

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=f"current path:{path_list}")
    list_label.pack()

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

Output for name:

enter image description here

Output for value and distance:

enter image description here

toyota Supra
  • 3,181
  • 4
  • 15
  • 19