0% found this document useful (0 votes)
23 views12 pages

B60 Python EXP - 05

The document is a lab manual for a Python GUI experiment using Tkinter, detailing the aim, prerequisites, outcomes, and procedures for creating a GUI application with various widgets. It includes sections on widget types, geometry management, and practical tasks for students to complete, such as implementing a student management system. Students are expected to submit their work and reflect on their learning outcomes and observations.

Uploaded by

Rajshree Dandge
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)
23 views12 pages

B60 Python EXP - 05

The document is a lab manual for a Python GUI experiment using Tkinter, detailing the aim, prerequisites, outcomes, and procedures for creating a GUI application with various widgets. It includes sections on widget types, geometry management, and practical tasks for students to complete, such as implementing a student management system. Students are expected to submit their work and reflect on their learning outcomes and observations.

Uploaded by

Rajshree Dandge
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/ 12

LAB Manual

PART A
(PART A : TO BE REFFERED BY
STUDENTS)

Experiment No.05
A.1 Aim:
To implement GUI with python containing widgets such as labels,
textbox,radio,checkboxes and custom dialog boxes.

A.2 Prerequisite:
1. C,JAVA Language

A.3 Outcome
After successful completion of this experiment students will be
able to
To demonstrate basic concepts in python

A.4 Theory& Procedure:

tkinter Programming
Tkinter is the standard GUI library for Python. Python when combined with
Tkinter provides a fast and easy way to create GUI applications. Tkinter
provides a powerful object-oriented interface to the Tk GUI toolkit.

Creating a GUI application using Tkinter is an easy task. All you need to do
is perform the following steps −

• Import the Tkinter module.

• Create the GUI application main window.

• Add one or more of the above-mentioned widgets to the GUI application.

• Enter the main event loop to take action against each event

triggered by the user. Example


#!/usr/bin/python

import tkinter
This would create a following window −
top = tkinter.Tk()
# Code to add widgets will go here...
top.mainloop()
Tkinter Widgets
Tkinter provides various controls, such as buttons, labels and text boxes used
in a GUI application. These controls are commonly called widgets.

There are currently 15 types of widgets in Tkinter. We present these widgets as well
as a brief description in the following table −

Sr.No. Operator & Description

1 Button

The Button widget is used to display buttons in your application.

2 Canvas

The Canvas widget is used to draw shapes, such as lines, ovals, polygons and
rectangles, in your application.

3 Checkbutton

The Checkbutton widget is used to display a number of options as checkboxes.


The user can select multiple options at a time.

4 Entry

The Entry widget is used to display a single-line text field for accepting values
from a user.
5 Frame

The Frame widget is used as a container widget to organize other widgets.

6 Label

The Label widget is used to provide a single-line caption for other widgets. It can
also contain images.

7 Listbox

The Listbox widget is used to provide a list of options to a user.

8 Menubutton

The Menubutton widget is used to display menus in your application.

9 Menu

The Menu widget is used to provide various commands to a user. These


commands are contained inside Menubutton.

10 Message

The Message widget is used to display multiline text fields for accepting values
from a user.

11 Radiobutton

The Radiobutton widget is used to display a number of options as radio buttons.


The user can select only one option at a time.

12 Scale

The Scale widget is used to provide a slider widget.

13 Scrollbar

The Scrollbar widget is used to add scrolling capability to various widgets, such
as list boxes.
14 Text

The Text widget is used to display text in multiple lines.

15 Toplevel

The Toplevel widget is used to provide a separate window container.

16 Spinbox

The Spinbox widget is a variant of the standard Tkinter Entry widget, which can
be used to select from a fixed number of values.

17 PanedWindow

A PanedWindow is a container widget that may contain any number of panes,


arranged horizontally or vertically.

18 LabelFrame

A labelframe is a simple container widget. Its primary purpose is to act as a


spacer or container for complex window layouts.

19 tkMessageBox

This module is used to display message boxes in your applications.

Let us study these widgets

in detail-
Let us take a look at how some of their common attributes.such as sizes, colors and fonts
are specified.

• Dimensions

• Colors

• Fonts

• Anchors

• Relief styles
• Bitmaps

• Cursors

Let us study them briefly −


Geometry Management
All Tkinter widgets have access to specific geometry management methods, which
have the purpose of organizing widgets throughout the parent widget area. Tkinter
exposes the following geometry manager classes: pack, grid, and place.

• The pack() Method − This geometry manager organizes widgets in blocks


before placing them in the parent widget.

• The grid() Method − This geometry manager organizes widgets in a table-like


structure in the parent widget.

• The place() Method − This geometry manager organizes widgets by


placing them in a specific position in the parent widget.

PART B
(PART B : TO BE COMPLETED BY STUDENTS)

(Students must submit the soft copy as per following segments within two hours of the
practical. The soft copy must be uploaded on the Blackboard or emailed to the concerned
lab in charge faculties at the end of the practical in case the there is no Black board access
available)

Roll No.B60 Name:Rajshree Dandge


Class :SE-B(COMP) Batch :B3
Date of Experiment:07/03/25 Date of Submission:21/03/25
Grade :
B.1 Document created by the student:

INPUT:
OUPUT:
B.2 Observations and learning:

• Tkinter Menu enhances navigation – Using Menu makes the app feel
more professional.

• Event handling is crucial – Button clicks, Listbox selection, and handling


user interactions made the GUI interactive.

• Use of Variables – StringVar() and IntVar() simplify data handling in


Tkinter.

• Data management can be improved – Storing students in a database


(SQLite, MySQL) would make the system more useful.

• Scrollbar for better UX – Large data needs scrollbars for easy navigation.

• Enhancing UI with Themes – Using ttk widgets gives a more modern


look to the application.

B.3 Conclusion:
Thus we have successfully implemented GUI with python containing
widgets such as labels, textbox,radio,checkboxes and custom dialog
boxes
B.4 Question of Curiosity

Q.1] Explain the difference between Checkbutton and Radiobutton widgets.


Ans:
Q.2] Discuss various components of GUI ?
Ans:

A GUI (Graphical User Interface) allows users to interact with software using visual elements instead
of text-based commands. Below are the main components of a GUI:

1️. Windows
• The main container that holds all other GUI components.
• Example: A login screen, a settings window.
In Tkinter: tk.Tk() creates the main window.

2️. Labels (Text Display)


• Displays static text or images.
• Used for headings, instructions, or descriptions.
In Tkinter: Label()
Example:
tk.Label(root, text="Welcome to the App").pack()

4. Entry (Textbox)
• Allows the user to input text.
• Example: Username, password fields.
In Tkinter: Entry()
Example:
entry = tk.Entry(root)
entry.pack()

5. Button:
• Triggers actions when clicked.
• Example: Submit, Cancel, OK buttons.
In Tkinter: Button()
Example:
tk.Button(root, text="Click Me", command=my_function).pack()

6. Radio Buttons
• Used when only one option should be selected from a group.
• Example: Gender selection (Male/Female).
In Tkinter: Radiobutton()
Example:
gender = tk.StringVar()
tk.Radiobutton(root, text="Male", variable=gender, value="Male").pack()
tk.Radiobutton(root, text="Female", variable=gender, value="Female").pack()

7. Checkbuttons (Checkboxes)
• Allows multiple selections.
• Example: Choosing hobbies, interests.
In Tkinter: Checkbutton()

Q.3] Compare the pack(), grid(), and place() methods in Tkinter.


Ans:

Q.4] Write a Python program to create a GUI-based Student Management System using
Tkinter.

Your program should:


1. Implement all 19 Tkinter widgets.
2. Include the following features:
• Student Registration & Attendance Tracking
• Course Selection & Performance Monitoring
• Menu Navigation, Alerts, and Data Display

Ans:

import tkinter as tk
from tkinter import messagebox, ttk
from tkinter import Menu

# Main App Window


root = tk.Tk()
root.title("Student Management System")
root.geometry("800x600")

# Student Database (List of Dictionaries)


students = []

# Function to Add Student


def add_student():
name = name_var.get()
age = age_var.get()
gender = gender_var.get()
course = course_var.get()
attendance = "Present" if attendance_var.get() else "Absent"
marks = marks_var.get()

if name and age and gender and course:


students.append({"name": name, "age": age, "gender": gender, "course": course,
"attendance": attendance, "marks": marks})
update_student_list()
clear_fields()
else:
messagebox.showwarning("Input Error", "All fields are required!")

# Function to Update Listbox with Students


def update_student_list():
student_listbox.delete(0, tk.END)
for student in students:
student_listbox.insert(tk.END, f"{student['name']} - {student['course']} -
{student['attendance']} - Marks: {student['marks']}")

# Function to Clear Input Fields


def clear_fields():
name_var.set("")
age_var.set("")
gender_var.set("")
course_var.set("")
attendance_var.set(0)
marks_var.set(50)

# Function to Show Student Details


def show_student_details():
selected = student_listbox.curselection()
if not selected:
messagebox.showwarning("Selection Error", "Select a student first!")
return
index = selected[0]
student = students[index]
messagebox.showinfo("Student Details", f"Name: {student['name']}\nAge:
{student['age']}\nGender: {student['gender']}\nCourse: {student['course']}\nAttendance:
{student['attendance']}\nMarks: {student['marks']}")

# Function to Exit Application


def exit_app():
root.quit()

# Top Menu
menu_bar = Menu(root)
file_menu = Menu(menu_bar, tearoff=0)
file_menu.add_command(label="Exit", command=exit_app)
menu_bar.add_cascade(label="File", menu=file_menu)
root.config(menu=menu_bar)

# Frames for Layout


frame_top = tk.Frame(root)
frame_top.pack(pady=10)

frame_middle = tk.Frame(root)
frame_middle.pack(pady=10)

frame_bottom = tk.Frame(root)
frame_bottom.pack(pady=10)

# Student Information Inputs


tk.Label(frame_top, text="Student Name:").grid(row=0, column=0)
name_var = tk.StringVar()
tk.Entry(frame_top, textvariable=name_var).grid(row=0, column=1)

tk.Label(frame_top, text="Age:").grid(row=1, column=0)


age_var = tk.StringVar()
tk.Spinbox(frame_top, from_=10, to=50, textvariable=age_var).grid(row=1, column=1)

tk.Label(frame_top, text="Gender:").grid(row=2, column=0)


gender_var = tk.StringVar()
tk.Radiobutton(frame_top, text="Male", variable=gender_var, value="Male").grid(row=2,
column=1)
tk.Radiobutton(frame_top, text="Female", variable=gender_var,
value="Female").grid(row=2, column=2)

tk.Label(frame_top, text="Course:").grid(row=3, column=0)


course_var = tk.StringVar()
courses = ["Math", "Science", "Computer Science", "History"]
ttk.Combobox(frame_top, textvariable=course_var, values=courses).grid(row=3, column=1)

attendance_var = tk.IntVar()
tk.Checkbutton(frame_top, text="Present", variable=attendance_var).grid(row=4, column=1)

tk.Label(frame_top, text="Marks:").grid(row=5, column=0)


marks_var = tk.IntVar(value=50)
tk.Scale(frame_top, from_=0, to=100, orient="horizontal", variable=marks_var).grid(row=5,
column=1)

# Buttons
tk.Button(frame_middle, text="Add Student", command=add_student,
bg="lightblue").grid(row=0, column=0, padx=10)
tk.Button(frame_middle, text="Show Details", command=show_student_details, bg="green",
fg="white").grid(row=0, column=1, padx=10)
tk.Button(frame_middle, text="Exit", command=exit_app, bg="red",
fg="white").grid(row=0, column=2, padx=10)

# Student Listbox with Scrollbar


scrollbar = tk.Scrollbar(frame_bottom)
scrollbar.pack(side="right", fill="y")
student_listbox = tk.Listbox(frame_bottom, width=70, height=10,
yscrollcommand=scrollbar.set)
student_listbox.pack(side="left", fill="both")
scrollbar.config(command=student_listbox.yview)

# Separator
ttk.Separator(root, orient="horizontal").pack(fill="x", pady=10)

# Progress Bar (Performance Monitoring)


progress_label = tk.Label(root, text="Overall Class Performance:")
progress_label.pack()

progress_bar = ttk.Progressbar(root, orient="horizontal", length=300, mode="determinate",


maximum=100, value=75)
progress_bar.pack()

# Run Main Loop


root.mainloop()

Output:

************************

You might also like