I have a long list of options for an option menu widget, but the menu always ends at option number 1167.
Here is the code:
from tkinter import *
root = Tk()
root.geometry( "200x200" )
options = [str(i) for i in range(2000)]
selected = StringVar()
selected.set( "1" )
drop = OptionMenu( root , selected , options )
drop.pack()
root.mainloop()
Theoretically, the option menu should go up to 2000, but it stops at 1167.
Here is an image: end of menu
Is there some way to fix this? should I use a different widget?
Thanks - Ian
CodePudding user response:
If anyone else gets themselves into this situation, I recommend the alternative I used: using a listbox instead. The code I wrote below isnt great, but it shows the basic idea.
For more info on the Listbox widget, visit: https://www.geeksforgeeks.org/python-tkinter-listbox-widget/ and https://www.geeksforgeeks.org/how-to-get-selected-value-from-listbox-in-tkinter/
from tkinter import *
root = Tk()
root.geometry("200x250")
#ol stands for Option List
def manage_ol(mode,items):
global selected,ol_frame,ol
if mode == 1:
ol_frame = Frame(root)
ol_frame.pack()
ol = Listbox(ol_frame)
for i in range(len(items)):
ol.insert(i,items[i])
ol.pack()
ol_select = Button(ol_frame,text = 'select',command = lambda: manage_ol(2,None))
ol_select.pack()
else:
selected = ol.curselection()[0]
print(ol.get(selected))
ol_frame.destroy()
items = ['a','b','c','d','e']
ol_start = Button(root,text = 'option list',command = lambda: manage_ol(1,items))
ol_start.pack()
root.mainloop()