Tkinter

How to Bind Multiple Commands to Tkinter Button

In this tutorial, we are going to see how to bind multiple commands to Tkinter Button. Several commands can be executed after clicking on the button.
 

How to Bind Multiple Commands to Tkinter Button

In the following example, we have created a function to change the text and a function to change the color of the button, both will be called at the same time, when the button is pressed.
 

 

from tkinter import *   

def two_funcs(*funcs):
    def two_funcs(*args, **kwargs):
        for f in funcs:
            f(*args, **kwargs)
    return two_funcs

def changeText():  
    btn['text'] = 'Welcome to StackHowTo!'
	
def changeColor():  
    btn['bg'] = 'Red'


gui = Tk()  
gui.geometry('200x100')  

btn = Button(gui, text = "Click here!", command = two_funcs(changeText, changeColor))
btn.pack()

gui.mainloop()

Output:


 
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *