Creating a basic GUI window (Python)

So far my Python programs have been very much text input based, i.e. users would need to use a command line to input values or progress in the program. This is okay for some users but the majority of modern computer users prefer using a Graphical User Interface (GUI), and Python does allow for a GUI.

I have created a quick little program just to show off a very basic GUI window interface, displaying some text and having an action carried out when a button is pressed.

——

#!/bin/python3

#geektechstuff

#Making a GUI window

#libraries to import

from tkinter import *

#create window

window = Tk()

#create window with text in it

text_in_window=Text(window,width=50,height=1)

text_in_window.insert(END,’We have made a window containing text’)

text_in_window.pack()

#create a window containing a button

#define an action  for the button

def button_action():

    window.destroy()

    

#put action and button together

button = Button(window, text=”Exit”, command=button_action)

button.pack()

——

This program makes use of the Tkinter library to create the GUI.

One thought on “Creating a basic GUI window (Python)

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.