Introduction

Basic Widgets

Toplevel Widgets

Geometry Management

Binding Functions

Working with Images in Tkinter

Tkinter Advance

Applications and Projects

Hello World in Tkinter

Starting with a "Hello World" program is the classic way to begin learning a new framework or library. Here's a tutorial to create a simple "Hello World" GUI application using Tkinter:

Hello World in Tkinter:

1. Prerequisites:

Before diving into code, ensure you have Python installed. Tkinter comes pre-installed with Python, so you don't need to install it separately.

2. Basic Hello World:

Step 1: Importing Tkinter

import tkinter as tk

Step 2: Create Main Application Window

root = tk.Tk()  # This creates the main window, `root`.
root.title("Hello World App")  # This sets the title of the window.

Step 3: Add a Label Widget with the Text "Hello, World!"

label = tk.Label(root, text="Hello, World!")  # Create a label widget.
label.pack(pady=20, padx=20)  # Place the label in the window with some padding.

Step 4: Run the Application Loop

root.mainloop()

3. Complete Code:

Now, combining all steps, here's the complete "Hello World" in Tkinter:

import tkinter as tk

# Create the main window
root = tk.Tk()
root.title("Hello World App")

# Create and pack a label
label = tk.Label(root, text="Hello, World!")
label.pack(pady=20, padx=20)

# Run the application loop
root.mainloop()

4. How to Run:

  • Save the above code in a file, say hello_world_tkinter.py.
  • Open your terminal or command prompt.
  • Navigate to the directory where you saved the file.
  • Run the program by typing python hello_world_tkinter.py.

A window should pop up displaying "Hello, World!".

With this basic structure, you can start adding other widgets, event bindings, and more to create fully functional GUI applications using Tkinter. Happy coding!