I have designed a Tkinter listbox which looks like this:
When I am in the main loop I can select the options 'A', 'B', etc and print it in the console. When I click proceed the window closes. Below is the code:
from tkinter import *
from tkinter import ttk
main = Tk()
main.title("Parameter Selection")
main.geometry("800x300")
main.configure(bg='mint cream')
frame = ttk.Frame(main, padding=(3, 3, 12, 12))
frame.grid(column=0, row=0, sticky=(N, S, E, W))
scrollbar = Scrollbar(main)
person = StringVar()
person.set("A B C D E")
lstbox1 = Listbox(frame, listvariable=person, selectmode=MULTIPLE, width=15, height=8)
lstbox1.grid(column=0, row=2, columnspan=2)
lstbox1.configure(background="skyblue4", foreground="white", font=('Aerial 13'))
def select1():
reslist = list()
seleccion = lstbox1.curselection()
for i in seleccion:
entry = lstbox1.get(i)
reslist.append(entry)
for val in reslist:
print(val)
return reslist
def quit():
main.destroy()
btn1 = ttk.Button(frame, text="Select Person Name", command=select1)
btn1.grid(column=1, row=3)
destroy_button = ttk.Button(frame, text="Proceed", command=quit)
destroy_button.grid(column=10, row=13)
main.mainloop()
Now I try to retrieve these entry value in another file. Code below:
import main
person = main.select1()
print(person)
Ideally, in combobox or some other Tkinter framework, I am able to retrieve value like this because quit()
function in the first code is destroying the window. But in this one I am getting this error from the listbox implementation file:
return self._getints(self.tk.call(self._w, 'curselection')) or ()**
_tkinter.TclError: invalid command name ".!frame.!listbox"