Home > Blockchain >  Why the menubar is not showing in my tkinter application?
Why the menubar is not showing in my tkinter application?

Time:08-26

Here is the code:

# -*- coding: utf-8 -*-
import tkinter as tk


class Application(tk.Tk):

    def __init__(self):
        super(self.__class__, self).__init__()
        self.title('test')
        self.geometry('300x350')
        self.setup_ui()

    def setup_ui(self):
        menubar = tk.Menu(self)
        menuFile = tk.Menu(menubar)
        menubar.add_cascade(label='File', menu=menuFile)
        menuFile.add_command(label='Exit', command=self.destroy)


if __name__ == '__main__':
    app = Application()
    app.mainloop()

After i run it,i got this a tkinter application without menubar:

a tkinter application without menubar

i don't how to fix it and what cause it.

Thanks.

CodePudding user response:

You never added the menubar to the root window. Add this line of code:

self.configure(menu=menubar)
  • Related