0

I am able to select items from my list but once I click the item I am not able to print the contents back to the terminal. I am also trying to figure out how to close the prompt once the user makes a selection. Any help would be greatly appreciated.

window.title('UTC Time Selection')

# for scrolling vertically
yscrollbar = Scrollbar(window)
yscrollbar.pack(side = RIGHT, fill = Y)

label = Label(window,
            text = "Select the UTC Time for Scanning to Start :  ",
            font = ("Times New Roman", 12), 
            padx = 10, pady = 10)
label.pack()
list = Listbox(window, selectmode = "single", 
            yscrollcommand = yscrollbar.set)

# Widget expands horizontally and 
# vertically by assigning both to
# fill option
list.pack(padx = 10, pady = 10,
        expand = YES, fill = "both")

x =["0000", "0100", "0200", "0300", "0400", 
    "0500", "0600", "0700", "0800", "0900",
    "1000", "1100", "1200", "1300", "1400", 
    "1500", "1600", "1700", "1800", "1900", 
    "2000", "2100", "2200", "2300"]

for each_item in range(len(x)):
    
    list.insert(END, x[each_item])
    list.itemconfig(each_item, bg = "white")

# Attach listbox to vertical scrollbar
yscrollbar.config(command = list.yview)
Button(window, text="Save & Exit", command=window.destroy).pack()
window.mainloop()
the_response = list.get(list.curselection())
print (the_response)
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • `list.get(list.curselection())` executes as soon as the code runs and window is displayed, not as you click on individual items. – OneCricketeer Aug 11 '21 at 21:31
  • 2
    Does this answer your question? [Getting a callback when a Tkinter Listbox selection is changed?](https://stackoverflow.com/questions/6554805/getting-a-callback-when-a-tkinter-listbox-selection-is-changed) – OneCricketeer Aug 11 '21 at 21:32
  • I will have to check on Monday. Our systems were down today. Thank you I appreciate it! – Code Noob Aug 13 '21 at 22:18
  • This definitely was helpful! Thanks @OneCricketeer – Code Noob Aug 18 '21 at 19:24

0 Answers0