Python GUI Tkinter
Ø Introduction
- Tkinter
is Python’s built-in GUI library
- It is
used to create desktop applications
- It
works on Windows, Linux, and macOS
Ø 2. Importing Tkinter
- Tkinter
is imported using import tkinter as tk
- No
external installation is required
- Tkinter
comes with standard Python
Ø Main Window
- The
main window is created using tk.Tk()
- It is
usually stored in a variable named root
- All
widgets are placed inside this window
Ø Window Properties
- The
window title is set using root.title()
- Window
size is set using root.geometry()
- Geometry
uses width × height format
Ø Widgets
- Widgets
are GUI components
- The label widget displays text
- The button widget performs actions
Ø User Input
- The entry widget is used for input
- User
data is read using. get()
- Entry
widgets are common in forms
Ø Layout Management
- Widgets
must be placed on the window
- .pack() is the simplest layout method
- .grid() arranges widgets in rows and columns
Ø Styling
- Colors
are set using fg and bg
- Fonts
are defined using tuples
- Padding
adds spacing around widgets
Ø Event Handling
- Button
actions are linked with functions
- Events
respond to user interaction
- command= is used for button events
Ø Main Loop
- GUI
runs using an event loop
- The
loop starts with root.mainloop()
- Without
it, the window closes immediately
Comments
Post a Comment