Advanced Python: GUI (Graphical User Interface)

Goal

Step 1: Using tkinter


import tkinter as tk

# Create window
window = tk.Tk()
window.title("My Program")

# Add label
label = tk.Label(window, text="Hello World")
label.pack()

# Start program
window.mainloop()

Explanation:

Task

Button Example


import tkinter as tk

def show_text():
    label.config(text="Button was clicked!")

window = tk.Tk()
window.title("Button Example")

label = tk.Label(window, text="Hello World")
label.pack()

button = tk.Button(window, text="Click me!", command=show_text)
button.pack()

window.mainloop()