I have the folling tkinter UI that I am building that on load does not immediately load the listbox data, and I'm not sure why. Instead, on load I get the scrollbar and an empty listbox (the button shows up fine too). As soon as I interact with the window at all, the contents of the listbox show up:
from tkinter import *
gui = Tk()
gui.eval('tk::PlaceWindow . center')
# gui.geometry("500x200")
top_frame = Frame(gui)
top_frame.pack(side=TOP)
bot_frame = Frame(gui)
bot_frame.pack(side=BOTTOM)
scrollbar = Scrollbar(top_frame)
scrollbar.pack(side=LEFT, fill=Y)
lb = Listbox(top_frame)
lb.pack()
def onselect(evt):
w = evt.widget
index = int(w.curselection()[0])
value = w.get(index)
print(index, value)
lb.bind('<<ListboxSelect>>', onselect)
lb.insert(0, *range(100))
scrollbar.config(command=lb.yview)
lb.config(yscrollcommand=scrollbar.set)
quit_button = Button(bot_frame, text="Quit", command=gui.destroy)
quit_button.pack()
mainloop()
It seems like there is some ordering in which the pack calls need to occur that I can't seem to get right.
How can I get the items to show up on window load while keeping the scrollbar on the left?
EDIT 1: system info:
platform.platform(): macOS-12.6.2-x86_64-i386-64bit
platform.python_version(): 3.10.6
tk.TkVersion: 8.6