Skip to content
Advertisement

Python, Tkinter entry get to function (error was with function call from button)

The entry value is just simply doesn’t get passed into the function, whatever I do.

JavaScript

Edit:
I just realized, if I add a variable to the function, it gets called as soon as I run the program, and it doesn’t care about the button; but if I don’t give it a variable, it works as it should, only when I push the button.

Here is the whole code

JavaScript

Advertisement

Answer

There’s a difference between calling a function and passing in a function’s name so it can be called later on. The ttk.Button command= expects a function name (or reference) to be passed in, so that the named or referenced function can be called later. You are calling the function rather than passing in its name, so things go awry.

Change:

JavaScript

to:

JavaScript

and you’ll be closer to your goal. The lambda tells Python not to call the function but rather just return a reference to it that can be used to call it later.

Once you do that, you’ll see that you have a typo in your function definition — you’re missing a colon at the end of the def statement. So, change:

JavaScript

to:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement