I intend to collect names in lists that will be used in a program, one at a time. The function does return a list and the whole program runs once, but after I call the function UserInput with the button:
ttk.Button(root, text='Add place', command= lambda:UserInput()).pack(ipadx=10, ipady=10)
it remains hanging. Even if I close the window, the program doesn't move to the next line:
print('outside function', places)
anymore.
The code is:
import tkinter as tk
from tkinter import simpledialog
from tkinter import ttk
root = tk.Tk()
def UserInput():
places = []
while True:
place = simpledialog.askstring('Input', 'Enter name',
parent=root)
if place == None: # 'Cancel'
continue
if place == '':
break
else:
places.append(place)
print(places)
return(places)
places = (UserInput()) # list of cities to visit
print('outside function', places)
ttk.Button(root, text='Add place', command= lambda:UserInput()).pack(ipadx=10, ipady=10)
root.mainloop()
Any help would be much appreciated. Thanking you in advance.