[Solved] menubar not defined in python


You are missing some important parts here.

You need to configure the menu first and you also need to add the cascade label.

Take a look at this code.

import tkinter

def hey():
    print("hello")

def myNew():
    # you forgot to use tkinter.Label here.
    mlabel = tkinter.Label(root, text="yo").pack()


root = tkinter.Tk()
root.title("Wizelane")
root.geometry('400x80+350+340')

my_menu = tkinter.Menu(root)

# configure root to use my_menu widget.
root.config(menu = my_menu) 

# create a menu widget to place on the menubar
file_menu = tkinter.Menu(my_menu, tearoff=0)

# add the File cascade option for drop down use
my_menu.add_cascade(label = "File", menu = file_menu)

# then add the command you want to add as a File option.
file_menu.add_command(label="New", command = myNew)

label = tkinter.Label(root, text="say hello")
label.pack()

hello = tkinter.Button(root, text="hello", command = hey)
hello.pack()

root.mainloop()

solved menubar not defined in python