how to create a button that applies all changes to the input text

Viewed 47

It's my first time on StackOverflow so please ask any clarification. So I want to create a button with the purpose of applying all changes including font size, style, and color after it asks for confirmation, the button is already there but it still doesn't have a function yet

edit: also, another button that resets the input, kinda like returns it to default.

# btn = Entry(window)
btn = Button(window, text = "Okay", command = confirm).place( x = 350, y = 30)
# btn.place( x = 350,
#            y = 30)

# btn2 = Entry(window)
btn2 = Button(window, text = "Cancel", command = remove).place( x = 350, y = 70)
# btn2.place( x = 350,
#             y = 70)
1 Answers

According to your question, the solution to your problem is to use an anonymous function or lambda that is responsable for gathering all the functions that you want to run at the same time in a single command.

A simple example can be as follows in a simple button:

def FirstFunction():
    print('Running function')

def SecondFunction():
    print('Running function')

btn = Button(window, text = "Okay", command=lambda:[(FirstFunction(), SecondFunction())]).place( x = 350, y = 30)

In real-world situations, in property sheets that use the OK or Apply buttons that run and apply each change made to the property sheet and they run multiple functions except for the Cancel button, that only closes the window without applying anything.

I recommend you read the Python and Tkinter documentation.

Related