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 response to “Creating a basic GUI window (Python)”

  1. Creating a basic GUI window V2 (Python) – Geek Tech Stuff Avatar

    […] previous attempt at creating a GUI window worked but I’ve since learned that when TKinter creates a window […]

    Like

Welcome to GeekTechStuff

my home away from home and where I will be sharing my adventures in the world of technology and all things geek.

The technology subjects have varied over the years from Python code to handle ciphers and Pig Latin, to IoT sensors in Azure and Python handling Bluetooth, to Ansible and Terraform and material around DevOps.

Let’s connect