commands in Tkinter commands in Tkinter tkinter tkinter

commands in Tkinter


This parameter will not accept two functions.The best way for you to solve this is to create a function that performs all other functions.

def main_menu():    passdef apending_to_text_file():    passdef commands():    main_menu()    apending_to_text_file()login_button = Button(    root, text="Click here to enter data",    command=commands)


A few issues here. and is a logical and, so you can't use it like that.

Second, you are calling your second function with the parentheses instead of passing the function itself. This means that you are passing the return value of a function as the command. So if we had a function

def my_func():    return 'hello'

passing in command = my_func will make the button call my_func(). If you try to pass in command = my_func(), you end up passing in the string hello which doesn't make sense.

Third, a solution would be to wrap both functions in a separate function. To do this inline, you can use a lambda function that calls both functions (in this case, you would want the parentheses). Or you can just define this function separately and call both of the functions you want.

Here are the examples:

def on_button_submit():    main_menu()    appending_to_text_file()

So then you an use this on_button_submit as the command for your button.

Or use a lambda function. Here is a quick example of how lambda function would work:

def func1():  print('in func1')def func2():  print('in func2')x = lambda : (func1(), func2())x()

So you can use the following as your button command:

lambda : (main_menu(), appending_to_text_file())


You can try something like this using lambda function

login_button = Button(root, text="Click here to enter data", command=lambda:[main_menu(),apending_to_text_file()])