Lazy cascading menu in Tkinter with postcommand

H

Humpty Dumpty

Hi folks, here's a challenge: I have a dynamically created cascading menu in
Tkinter that can be quite large because it is created from a file. I tried
using lazy creation so only the menu item that is actually selected by the
user gets children menu items created under it, but that fails.

I did this by use of postcommand callback, in which I dynamically add the
children menu items to the parent. However, a print statement in the
postcommand callback shows that:
1) *ALL* cascading menu items in a hierarchy get the postcommand event,
every time the user selects the top menu item
2) all children that have just been added to a cascading menu item in the
postcommand callback will hear that postcommand event

So in the end, the first time the user clicks on the top menu item, the
whole menu hierarchy gets created (though only the top level is displayed of
course).

Anyone know how to get around this? I'm considering bypassing the built-in
cascading menu and creating my own via popup menus and filtering for "on
entry" of the buttons, but there should be a simpler method.

Thanks in advance for any help,
Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top