Tkinter Basics – Study Notes (English)
1. Creating a Window
- Import Tkinter using: import tkinter as tk
- Create a window: window = [Link]()
- Set a title: [Link]("My App")
- Set size: [Link]("400x300")
- Start the window loop: [Link]()
2. Adding a Label
- A label displays text inside the window.
Example:
label = [Link](window, text="Hello!", font=("Arial", 14))
[Link]()
3. Adding a Button
- A button triggers a function when clicked.
Example:
def on_click():
[Link](text="Button clicked!")
btn = [Link](window, text="Click Me", command=on_click)
[Link]()
4. Getting User Input (Entry)
- Entry is used for text input fields.
Example:
entry = [Link](window)
[Link]()
- Getting the entered value:
value = [Link]()
5. Updating Text Dynamically
- You can change label text using:
[Link](text="New Text")
6. Pack Layout Manager
- pack() arranges widgets vertically in order.
- Useful options:
pack(pady=10) # vertical spacing
pack(side="left") # aligning
7. Summary of What You Learned Today
- How to create a Tkinter window
- How to add label, button, and entry
- How to handle button clicks with functions
- How to read user input
- How to update widgets dynamically