Python – GUI (Button)

In this tutorial, I will be demonstrating Graphical User Interface
Programming using Python.

The codes are below:



Our output should be the same as below:




There are several points needed to be explained here.
The import keyword on the first two lines are used to use the libraries native to Python.
Tkinter and tkMessageBox are used for basic GUI Programming.

The lines:

top = Tkinter.Tk()

are used to initialize the main form of the program

On this part:

def helloCallBack():
tkMessageBox.showinfo(“Hello Python”, “Hello World”)

  • the def keyword is the same as the function block in other languages
  • the showinfo has two parameters which are:
    “Hello Python” is the used as the title of the Message Box
    “Hello World” is the message inside the Message Box

The line:

B = Tkinter.Button(top, text =”Hello”, command = helloCallBack)

is the initialization of the Button which contains three parameters
top is the position of the button inside the box
text is the String that is used to name the button
command points to function where the button goes when it is clicked


Thank you for reading my post.
Don’t forget to leave a comment.