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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s