1

I have recreated the problem in my code here. I probably have defined the list incorrectly.

import tkinter as tk
Name=("")
j=0
AnimalNameList=["Badger","Beaver","Buffalo","Bull","Bulldog","Cobra","Curlew","Eagle","Falcon","Fox","Gannet","Hawk","Kestrel","Lion","Merlin","Otter","Owl","Panther","Peewit","Raven","Seagull","Seal","Stag","Swift","Tiger","Wolf","Woodpecker","Woodpigeon"]
for i in AnimalNameList:
    j=j+1
    print(i)
print(j)
root=tk.Tk()
Animals=tk.OptionMenu(root,Name,AnimalNameList)
Animals.grid(row=1,column=1)
root.mainloop()
Ligen
  • 13
  • 3
  • Any particular reason your last line is just `root.mainloop`, with no parentheses? – user2357112 Oct 17 '18 at 18:53
  • 1
    Unpack your list: `Animals = tk.OptionMenu(root, Name, *AnimalNameList)`, and what @user2357112 said, call mainloop with `root.mainloop()` – r.ook Oct 17 '18 at 18:58

1 Answers1

1

You can test how many values it can take.

Here is a simple example:

import tkinter as tk

long_list = []
for i in range(50000):
    long_list.append(i)

root = tk.Tk()
Animals=tk.OptionMenu(root, "start", *long_list)
Animals.grid(row=1, column=1)
root.mainloop()

The above works for me though it takes a few seconds to load. If I try to do 70,000 instead it fails. Thought the max elements in a list can be very large according to this post I imagine the limitation may be based on memory. However you problem is not due to having too many options.

You are forgetting the * for your argument on the OptionsMenu. This is required when passing a list of options otherwise it will give you one drop down item with all the values from the list in one row.

So change this:

Animals=tk.OptionMenu(root,Name,AnimalNameList)

To This:

Animals=tk.OptionMenu(root,Name,*AnimalNameList)

Also make sure you do root.mainloop() as the parentheses are required.

Mike - SMT
  • 14,784
  • 4
  • 35
  • 79