A Complete seminar on GUI Development in python

18547Mymoon 23 views 30 slides Sep 04, 2024
Slide 1
Slide 1 of 30
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30

About This Presentation

A complete presentation on how we can code Graphical user inteface using Python


Slide Content

GUI Development in Python

Introduction to GUI Programming
Designing and building graphical interfaces that allow
users to interact with software using visual elements.
●Widgets: Basic visual elements like buttons labels, text
boxes, and menus.
●Layout: Arranging widgets in a window or container.
●Events: User interactions like clicks, key presses, and
mouse movements.
●Event Handling: Writing code to respond events.

Introduction to GUI Programming
GUI Frameworks

1.Tkinter: Built-in python library for creating simple GUIs.
2.PyQt: Powerful framework for building complex GUIs
3.wxPython: Cross-platform framework for building GUIs.
4.JavaFX: Modern framework for building GUIs.
5.Swing : Older framework for building GUIs.

Basic Steps:
→ Choose a framework→ Design the interface
→ Write event handlers→ Assemble the GUI
→ Test and refine

Installing PyCharm
Windows :
→ Download PyCharm installer.
→ Run installer and follow
prompts.
→ Choose installation location
and components.

MacOs :
→ Download PyCharm disk
image.
→ Drag PyCharm icon to
Application folder.
→ Launch PyCharm.
Addition Steps :
→ Activate PyCharm with license.
→ Configure project interpreter.
→ Install additional plugins

Introduction to GUI Programming on PyCharm
Step - 1 : Create a New project

Step - 2 : Install GUI library

Stap - 3 : Create a GUI window

Step - 4 : Add GUI widgets

Step - 5 : Run the GUI App

Introduction to Tkinter
Tkinter is a python’s de-facto standard GUI package.

Tkinter Widgets :
1.Label : Displays text or images.
2.Button : A Clickable button.
3.Entry : A text input field.
4.Text : A multi-line text box.
5.Frame: A container for other widgets.

Introduction to Tkinter
Basic Tkinter Concepts :
1.Root Window : The main application window.
2.Widgets : GUI elements like buttons, labels, etc.
3.Layout Managers : Arrange widgets in the window.
4.Events : User interaction like clicks,key presses, etc
5.Callbacks : Functions that handle events.

Introduction to Tkinter
Titles :

Setting the window title :

1.Use the title() method :

root = (link unavailable)()
root.title(“My GUI App”)

Introduction to Tkinter
Setting the window Icon :

1.Use the iconbitmap() method for Windows :
``
root = (link unavailable)()
root.iconbitmap(“icon.ico”)
``
2.Use the iconphoto() method for macOS and Linux :
``
root = (link unavailable)()
icon = tk.PhotoImage(file=”icon.png”)
root.iconphoto(False, icon)
``

Layouts in Tkinter
Three layout managers to arrange widgets in window :

1.Pack :
→ Simple and easy to use.
→ widgets are added in a vertical or horizontal box.
→ It can fill, expand, side, padx, pady.

Ex:
``
label = tk.Label(root, text=”Label”)
label.pack(fill=”x”,padx=10,pady=10)
``

Layouts in Tkinter
Three layout managers to arrange widgets in window :

2.Grid :
→ More flexible and powerful.
→ Widgets are arranged in a table-like structure.
→ Options: row, column, stickey, padx, pady.

Ex:
``
label = tk.Label(root, text=”Label”)
label.grid(row=0, column=0, padx=10, pady=10)
``

Layouts in Tkinter
Three layout managers to arrange widgets in window :

3.Place :
→ Precise control over widgets placements.
→ Widgets are placed at specific x, y coordinates.
→ Options: x, y, relx, rely, anchor.

Ex:
``
label = tk.Label(root, text=”Label”)
label.place(x=50, y=50, anchor=“center”)
``

Introduction to Widgets in Layout
Common widgets and their roles in a layout:

1.Label
2.Button
3.Entry
4.Text
5.Frame
6.CheckButton
7.RadioButton
8.ListBox
9.ScrollBar
10. Canvas
11.Menu
12. Scale

Introduction to Grid Layout
It's a Powerful tool for arranging widgets in a table-like structure.

●Rows and Columns : Divide window into rows and columns.
●Widgets : Place widgets in specific cells of the grid.

Grid Operations :

1.Row : Specify the row number
2.Column : Specify the column number.
3.Sticky : Align widget within cell
4.Padx and pady : Add horizontal and vertical padding around widget
5.Rowspan and columnspan : Make widget span multiple rows or columns

Integration using GUI Designing User Interface
Integrating GUI design with user interface design involves creating a
visually appealing and interactive layout for your application.

1.Plan your Layout
2.Choose a color scheme
3.Select fonts
4.Design Widgets
5.Use layout Managers
6.Add Spacing and padding
7.Implement navigation
8.Test and refine

Integration using GUI Events
It involves connecting widgets to actions and events.

1.Define event handlers: Write functions that responds to events.
2.Blind Events to widgets: Use methods like command or bind to
link event handlers to widgets.
3.Handle events: Perform actions when events occur.

Common GUI Events :
●Button clicks
●Key presses
●Mouse clicks
●Window close

Integration using GUI Functions
Connecting widgets to actions and events and using functions to
perform tasks.

1.Define functions : Perform tasks such as calculations, data
processing.
2.Create widget : Add buttons, labels, text entries etc.
3.Bind Functions to widget : Use methods like command or bind
to link functions to widget.
4.Handle events : Respond User Interface.

Common GUI Functions are Button commands, Calculation, Data
validation and file handling functions.

Drop down menu
Customizations of a drop down menu :
●Changing the option list
●Setting a default value using variable.set()
●Using variable.get() to retrieve the selected option
●Blinding a function to the menu selection using variable.trace()
EX:
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
dropdown = ttk.Combobox(root, values=["Option 1",
"Option 2", "Option 3"])
dropdown.pack()
root.mainloop()

Toolbar
Customizations of a Toolbar menu :
●Changing the button text and commands
●Adding more buttons or widgets
●Using pack, grid, place to arrange widgets in the toolbar
●Configuring the toolbar appearance
EX:
import tkinter as tk
root = tk.Tk()
root.title("Simple GUI")

# Run the application
root.mainloop()

Status Bar
Display information about the current state of the application.

Functions of a status bar :
●tk.Label : Display text or image
●tk.Progressbar : display progress of operation
●tk.Button : Performs actions when clicked

EX: label = tk.Label(root, text="This is a simple widget")
label.pack()
status_bar = tk.Label(root, text="Status: Ready", anchor=tk.W)
status_bar.pack(side=tk.BOTTOM, fill=tk.X)
root.mainloop()

Message Box
Display Message to the user

Functions used in Message box :
●askokcancel
●askretrycancel
●askyesno
●askyesnocancel
EX:def show_message():
messagebox.showinfo(”Message”, “Hello world”)
button = tk.Button(root, text=”show message”,
command = show_message)
button.pack()
root.mainloop()

Scale Widget
Allows user to select a value from a continuous range.

Functions used in Scale widget :
●label
●tickinterval
●length
EX:scale = tk.Scale(root, from_=0, to=100, orient =”horizontal”)
scale.pack()
def get_value():
print(scale.get())
button = tk.Button(root, text=”Get value”, command=get_value)
button.pack()
root.mainloop()

SpinBox Widget
Create a single line input field that allows users to enter a value from a specified
range

Functions used in Message box :
●formate
●increment
●wrap
EX:spinbox = (link unavailable)()
root.title(“GUI with spinbox widget”)
def get_value():
print(spinbox.get())
button = tk.Button(root, text=”Get value”, command=get_value)
button.pack()

Graphics and Shape line Graphics
Refers to the visual representation of shapes,lines and other elements.


EX:canvas = tk.Canvas(root, width=400,height=400)
canvas.pack()
canvas.create_line(10, 10, 390, 340, fill=”red”)
canvas.create_rectangle(50, 50, 150,150, fill=”green”)
canvas.create_oval(200, 200, 300, 300, fill=”green”)

root.mainloop()

Graphical Box
A rectangular area in a graphical UI that can contain various elements
Such as..,
1.Text
2.Images
3.Shapes
4.Icons
5.Buttons
6.Other GUI elements
Types of Graphical Boxes :
●Frames
●Panels
●Window
●Dialog boxes

Graphical Shape - Canvas
It can draw and manipulate various shapes such as..,
1.1. Lines
2.Rectangles
3.Eclipses
4.Polygons
5.Circles
6.Arcs
7.Curves
Customize the shape by using..,
●fill
●outline
●width
●dash

Images in GUI
Add images by using the PhotoImage class for PNG,PPM and PGM
images or the ImageTk module for other formats like JPEG.

EX: image = tk.PhotoImage(file=”image.png)

pil_Image = Image.open(“image.jpg”)
image_tk = ImageTk.PhotoImage(pil_image)

label = tk.Label(root, image=image)
label.pack()

label_tk = tk.Label(root, image=image_tk)
label_tk.pack()

ListBox
Displays a list of items from which a user can select one or more items.

●selectmode : Allows single or multiple selections

●delete : Method to remove items

●Insert : Method to add items at specific positions

●size : To set the number of items displayed.

ComboBox
Combines a text field with a drop down list of options.

●state : read only to prevent user input

●current : Method to set the current option

●Set : Method to set the text entry field

●bind : Method to attach events to the combobox

Treeview
Displays a hierarchical collection of items in a tree like structures.

●selectmode : Allows single or multiple selections.

●delete : Method to remove items.

●Insert : Method to add items at specific positions.

●item : Method to access and modify item attributes.

●bind : method to attach events to the treeview.