Could somebody help me with this. I am passing values from one listbox to another and back again in tkinter, but I need to output the current list (values in box on right).The values in this box will change because they can be moved back to the original box (left). I have tried using the return statement to return the current list but keep getting nothing printed out
from tkinter import *
from tkinter import ttk
my_window = Tk()
my_frame_in = Frame(my_window)
my_frame_in.grid(row=0, column=0)
my_frame_out = Frame(my_window)
my_frame_out.grid(row=0, column=1)
listbox_events = Listbox(my_frame_in, height='5')
listbox_events.grid(row=0, column=0, padx=10, pady=10)
listbox_events_filtered = Listbox(my_frame_out, height='5')
listbox_events_filtered.grid(row=0, column=2, padx=(0, 10), pady=10)
my_instructions = Label(my_window, text='Use arrow keys to move selected items')
my_instructions.grid(row=1, column=0, columnspan=3, pady=(0, 10))
my_list_events = ['A', 'B', 'C', 'D']
for item in my_list_events:
listbox_events.insert(END, item)
current_list = []
def select_events():
listbox_events_filtered.insert(END, listbox_events.get(ANCHOR))
listbox_events.delete(ANCHOR)
current_list.append(ANCHOR)
return current_list
def deselect_events(event=None):
listbox_events.insert(END, listbox_events_filtered.get(ANCHOR))
listbox_events_filtered.delete(ANCHOR)
# ref https://effbot.org/tkinterbook/tkinter-events-and-bindings.htm
listbox_events.bind('<Right>', select_events)
listbox_events.bind('<Left>', deselect_events)
for item in current_list:
print(item)
mainloop()