Why the menubar is not showing in my tkinter application?

Question:

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.

Asked By: Danhui Xu

||

Answers:

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

self.configure(menu=menubar)
Answered By: Bryan Oakley
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.