pythontkintertkinter-menu

Trying to add menu option using tkinter


Trying to add menu option but my code crash. tried multiple ways to add but not sure how to do that. any hint will helpful.!!!

I tried many ways posted on google also tried to write some code but somewhere it's fail to bind Menu and Tkinter

Any references will appreciate.


Solution

  • Create a tk.Menu and add commands using menu.add_command. Read here for more information about tkinter menus and how to do things like adding submenus. For your code, you can add a menu like this:

    ...
    tk.Tk.__init__(self)
    #self._GUID()
    self.x = self.y = 0
    self.menu = tk.Menu(self)
    self.menu.add_command(label = "Menu command name", command = self.doSomething)
    self.config(menu = self.menu)
    self.canvas = tk.Canvas(self, width=512, height=512, cursor="cross")
    ...