0

I have a menu that when clicked should run a function. There are no errors but when the user clicks on the menu it does not do anything.

After reading another stack overflow question I added in lamda functions to the command however it does the same thing both with and without the lambda. Python Tkinter Menu Command Not Working

menubar = Menu(self.master)
self.master.config(menu=menubar)

menubar.add_command(label = "Add Items", command= lambda: self.Add_Items)
menubar.add_command(label = "Make A Purchase", command= lambda: self.Transactions)
menubar.add_command(label = "Make A Return", command= lambda: self.Returns)

This is the menu

def Add_Items(self):
    label = tk.Label(self, text="Add Items")
    label.grid()

This is the function that it should run.

What am I missing?

  • The answer below by @FrainBr33z3 fixes the issue and the code runs (technically) however no labels are added to the frame despite me calling grid. – Callie Lewis Mar 17 '20 at 11:48
  • indeed it does. The label is drawn on the window with the text `Add Items`. Maybe there is an issue with some other part of your code. Anyhow, as the answer solves your problem, it is always better to open another question and not form a chain here – FrainBr33z3 Mar 17 '20 at 11:53
  • Thank you, I just wanted to check it wasn't something stupid I had done. I will try and see what I have done @FrainBr33z3 – Callie Lewis Mar 17 '20 at 12:01

1 Answers1

1

The error occurs as there is a lack of parenthesis () in the command option with lambda. Do either one of the following:

menubar.add_command(label = "Add Items", command = Add_Items)

OR

menubar.add_command(label = "Add Items", command = lambda: Add_Items())
FrainBr33z3
  • 1,085
  • 1
  • 6
  • 12