Table of content
Installation
Create a window
Create a label
Create button
Close button
Full Code
Output
Installation
Before starting, make sure to install tkinter in your system
sudo apt update
sudo apt install python3-tk
Create a window
import tkinter as tk
# Create the main window
root = tk.Tk()
# Window title
root.title("Simple GUI")
# Window Size (width x height)
root.geometry("400x300")
Create a label
# Create a label
label = tk.Label(root, text="Hello, World!")
# Add the label to the window with vertical padding
label.pack(pady=20)
Create a button
# Create a close button
close_button = tk.Button(root, text="Close", command=root.quit)
# Add vertical padding
close_button.pack(pady=20)
Full Code
import tkinter as tk
# Create the main window
root = tk.Tk()
# Window title
root.title("Simple GUI")
# Window Size (width x height)
root.geometry("400x300")
# Create a label
label = tk.Label(root, text="Hello, World!")
# Add the label to the window with vertical padding
label.pack(pady=20)
# Create a close button
close_button = tk.Button(root, text="Close", command=root.quit)
# Add vertical padding
close_button.pack(pady=10)
# Run the main loop
root.mainloop()
Output