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 thought on “Creating a basic GUI window V2 (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.