How to handle a Button click event

You already had your event function. Just correct your code to:

   """Create Submit Button"""
    self.submitButton = Button(master, command=self.buttonClick, text="Submit")
    self.submitButton.grid()

def buttonClick(self):
    """ handle button click event and output text from entry area"""
    print('hello')    # do here whatever you want

This is the same as in @Freak’s answer except for the buttonClick() method is now outside the class __init__ method. The advantage is that in this way you can call the action programmatically. This is the conventional way in OOP-coded GUI’s.

Leave a Comment