A
A
Arthur Samurai2020-07-21 11:12:42
Python
Arthur Samurai, 2020-07-21 11:12:42

How to pass arguments to a function using Tk?

def func(arg1, arg2):
       print(arg1+arg2)
Class window:
       enter_arg1 = Entry()
       btn = ttk.Button(Button-1, func)

There is a question, when the button is pressed, the func function will be executed, there is also a field for entering an argument, now the question. How to pass a user-supplied argument to the function itself?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kamenyuga, 2020-07-21
@zvepb

The standard pythonic approach is to wrap the function call in a lambda function:

btn = ttk.Button(Button-1, lambda x=1, y=2: func(x, y))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question