General Discussions

Basic GUI in Python

Indian Bloggers

This post helps you in building a basic GUI for python using tkinter. Python 3.4 is used for coding.

# Import the tkinter
from tkinter import *

root = Tk()
var = StringVar()

# Set the Layout as desired and the title for the window
root.title("Title Here")

# Display an image
# The image gets displayed at the centre of the window
image = PhotoImage(file="give-image-name-with-path.gif")
labelp = Label(image=image)
labelp.pack(), rely=0.2, anchor=CENTER)

# Display a text prompt say asking a name
key_display = Label(root, text="Enter the name")
key_display.pack(), rely=0.4, anchor=CENTER)

# Set a input box to collect a user input
# The input can be extratced from the variable 'var'
user_input = Entry(root, bd=7,textvariable=var)
user_input.pack(), rely=0.4, anchor=CENTER)

# Get a button at the centre
B = Button(root, text ="-- Button Name --", command=function_name_you_want_to_exe)
B.pack(), rely=0.5, anchor=CENTER, height=50, width=150)


Let me Know What you Think!

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s