GUI Programming in Python
(Tkinter) – Notes
📌 1. Introduction to GUI
🔹 What is GUI?
GUI (Graphical User Interface) allows users to interact with software using:
Buttons
Icons
Text fields
👉 Instead of typing commands, users click and interact visually
🔹 Examples of GUI Applications
Calculator
Notepad
Web browsers
Mobile apps
📌 2. GUI vs CLI
GUI Programming in Python (Tkinter) – Notes 1
Feature GUI CLI
Interaction Visual (buttons, icons) Text commands
Ease of Use Easy for beginners Requires knowledge
Examples Calculator, Chrome Terminal, CMD
📌 3. What is Tkinter?
🔹 Definition
Tkinter is Python’s built-in library for creating GUI applications.
👉 It is:
Simple
Beginner-friendly
No extra installation required
🔹 Import Tkinter
importtkinterastk
📌 4. Basic Window Setup
🔹 Create Main Window
importtkinterastk
root=[Link]()
[Link]()
🔹 Important Components
Component Description
Tk() Creates main window
mainloop() Runs the application
GUI Programming in Python (Tkinter) – Notes 2
Component Description
title() Sets window title
geometry() Sets window size
🔹 Example
[Link]("My App")
[Link]("400x300")
📌 5. Key Widgets in Tkinter
Widgets are elements placed on GUI.
🔹 1. Label
Displays text
[Link](root,text="Hello").pack()
🔹 2. Entry
Takes user input
entry=[Link](root)
[Link]()
🔹 3. Button
Triggers actions
[Link](root,text="Click Me").pack()
🔹 4. Canvas
Used for drawing shapes/images
📌
GUI Programming in Python (Tkinter) – Notes 3
📌 6. Layout Management
Controls how widgets are arranged.
🔹 1. Pack Layout
Simple
Auto-arranges widgets
[Link]()
🔹 2. Grid Layout
Table-like structure
[Link](row=0,column=1)
🔹 3. Place Layout
Exact positioning
[Link](x=50,y=100)
📌 7. Event Handling
🔹 What is Event?
An event is an action like:
Button click
Key press
🔹 Example: Button Click
defclick():
print("Button clicked")
GUI Programming in Python (Tkinter) – Notes 4
[Link](root,text="Click",command=click).pack()
📌 8. Mini Project: Login Form
🔹 Features:
Username input
Password input
Login button
🔹 Example Code
importtkinterastk
deflogin():
username=[Link]()
password=[Link]()
print(username,password)
root=[Link]()
[Link](root,text="Username").pack()
user=[Link](root)
[Link]()
[Link](root,text="Password").pack()
pwd=[Link](root,show="*")
[Link]()
[Link](root,text="Login",command=login).pack()
[Link]()
📌 9. Advanced Project: Finance Tracker
GUI Programming in Python (Tkinter) – Notes 5
🔹 Features:
Add income/expenses
Store data
Show reports
User-friendly interface
📌 10. Real-World Applications
✅ Inventory System
✅ File Organizer
✅ Billing Software
✅ Login Systems
👉 Tkinter is used to build desktop applications
📌 11. Best Practices
Keep UI simple
Use proper layout
Label everything clearly
Maintain consistent design
📌 12. Common Mistakes ⚠️
Spelling mistakes in geometry()
Forgetting mainloop()
Wrong widget placement
Not handling events properly
📌 13. Final Understanding
If students understand:
GUI Programming in Python (Tkinter) – Notes 6
Window creation
Widgets
Layout
Events
👉 They can build:
Desktop apps
Forms
Tools
📌 14. Key Takeaway
GUI makes programs user-friendly
Tkinter makes GUI easy in Python
GUI Programming in Python (Tkinter) – Notes 7