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?

3
  • 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. Commented Mar 17, 2020 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 Commented Mar 17, 2020 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 Commented Mar 17, 2020 at 12:01

1 Answer 1

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())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.