Creating a basic GUI window V2 (Python)

My previous attempt at creating a GUI window worked but I’ve since learned that when TKinter creates a window it uses a class structure that creates a super (root) window. Frames can then be created within this window to hold applications (buttons, labels etc). I’ve updated my (basic) program so that it now uses these concepts.

——

#!/bin/python3

#geektechstuff

#Making a GUI window V2

#libraries to import

from tkinter import *

#create window

root = Tk()

#sets the windows title

root.title(“geektechstuff”)

#sets windows width x height

root.geometry(“300×150”)

#frame to hold the labels / buttons

app = Frame(root)

app.grid()

#create label

text_label = Label(app,text=”GeekTechStuff window now contains text”)

text_label.grid()

#define an action for the button, in this case it closes the root window

def button_action():

    root.destroy()

#Add button

button_1 = Button(app,text=”GeekTechStuff Button!”, command=button_action)

button_1.grid()

    

#start event loop – creates the window with the above labels and buttons

root.mainloop()

——

One response to “Creating a basic GUI window V2 (Python)”

  1. File Browser V1 (Python) – Geek Tech Stuff Avatar

    […] merge idea better with some GUI driven fun rather than command line, and building on my previous GUI attempt. To do this I decided I would need a file explorer/file browser […]

    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