0% found this document useful (0 votes)
7 views13 pages

Unit-4 GUI

The document introduces event-driven programming, highlighting its reliance on user actions to trigger functions, contrasting it with procedural programming. It explains Tkinter as Python's standard GUI library, providing tools for building graphical applications. Additionally, it includes a simple example of a Tkinter GUI and outlines assignments for creating various GUI elements.

Uploaded by

madhurb2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views13 pages

Unit-4 GUI

The document introduces event-driven programming, highlighting its reliance on user actions to trigger functions, contrasting it with procedural programming. It explains Tkinter as Python's standard GUI library, providing tools for building graphical applications. Additionally, it includes a simple example of a Tkinter GUI and outlines assignments for creating various GUI elements.

Uploaded by

madhurb2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Unit-4

Graphical User Interfaces


Event-Driven Programming Paradigm
What is Event-Driven Programming?

● In event-driven programming, the flow of the program is determined by events like button clicks, keypresses, or user inputs.

● Unlike procedural programming (which executes line by line), event-driven programs wait for user actions (events) to trigger
specific functions.
Tkinter Module
What is Tkinter?

● Tkinter is Python’s standard GUI library.

● It provides a set of widgets (buttons, labels, text fields, etc.) for building graphical applications.
Creating Simple GUI Elements
Widget Attributes
Nested Frames
Complete GUI Example
A basic Tkinter GUI with labels, buttons, entry fields, and message boxes.
import tkinter as tk
from tkinter import messagebox

def greet():
user_name = entry.get()
if user_name:
messagebox.showinfo("Greeting", f"Hello, {user_name}!")
else:
messagebox.showwarning("Warning", "Please enter your name.")
# Create main window
root = tk.Tk()
root.title("Simple GUI")
root.geometry("300x200")

# Add widgets
label = tk.Label(root, text="Enter your name:", font=("Arial", 12))
label.pack(pady=5)
entry = tk.Entry(root)
entry.pack(pady=5)

button = tk.Button(root, text="Greet", command=greet)


button.pack(pady=5)

# Run the application


root.mainloop()
Assignment
● Design a GUI with a button that shows a message box displaying "Hello,
User!" when clicked.
● Create a Tkinter GUI with two buttons: one changes the background color to
red and the other to blue.
● Write a Python program to create a GUI with radio buttons and display the
selected option.
● Write a Python program to create a simple login GUI with username and
password fields.
● Explain different types of widgets in tkinter.

You might also like