[Python] How can I add a menu before the first in Python tkInter?

Discussão em 'Python' iniciado por Stack, Janeiro 19, 2025.

  1. Stack

    Stack Membro Participativo

    I’m writing some code to add a menu to a tkInter application. Here is a working sample:

    import tkinter

    main = tkinter.Tk()
    main.title('Menu Test')

    menubar = tkinter.Menu(main)
    main['menu'] = menubar

    m = tkinter.Menu()
    menubar.add_cascade(menu=m, label='First')
    m.add_command(label='Thing', command=lambda: print('thing'))

    m = tkinter.Menu()
    menubar.add_cascade(menu=m, label='Second')
    m.add_command(label='Whatever', command=lambda: print('whatever'))

    # How to add another menu before 'First' ?

    main.mainloop()


    Is it possible to add another menu before the first menu (First) ?

    Obviously, in this simple case, I can simply define it first, but I want to write a routine which populates a menu from a dictionary.

    Continue reading...

Compartilhe esta Página