Thanks to furas I have the following code for ListBox:
import tkinter as tk
def on_button():
# for i, var in enumerate(o_vars):
# print('OptionMenu {}: {}'.format(i, var.get()))
# print()
print('ListBox:', l.curselection())
for i in l.curselection():
print('option:', OPTIONS[i])
print()
# --- main ---
OPTIONS = ["Script 1","Script 2","Script 3","Script 4","Script 5"]
root = tk.Tk()
# --- Listbox ---
tk.Label(root, text='Listbox', bg='#aaa').pack(fill='x')
l = tk.Listbox(root, selectmode='multiple')
l.pack()
l.insert('end', *OPTIONS)
# --- others ---
b = tk.Button(root, text='OK', command=on_button)
b.pack(fill='x')
root.mainloop()
When I run it, it gives me the following pop-up (image shown below). I then make my selections.
This is where I am stuck... I want to say if user selected Script2 print 'script 2'. If user selected script 5, print 'script 5'.
Below is the code I tried but it errored out:
if l.curselection() == 'Script1':
print ('test')
if l.curselection() == 'Script2':
print ('test2')
TclError: invalid command name ".92911768"
Also, how do I add a "Quit" button below "OK"?
*Any help is greatly appreciated


CamelCasenames for classes - ie.SimpleFormAppto make code more readable - PEP 8 -- Style Guide for Python Codeprint()to see what you have in variables and which part of code is executed. So useprint(l.curselection())to see what you get.