0% found this document useful (0 votes)
21 views27 pages

Day-7 AdvPython WS

Python
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)
21 views27 pages

Day-7 AdvPython WS

Python
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/ 27

Day7

GUI Programming

Introduction to GUI Programming


Graphical User Interface (GUI) programming allows users to interact with software applications
through graphical elements like windows, buttons, and text fields. Python provides several
libraries for creating GUIs, with Tkinter being the most commonly used.

Tkinter Overview
● Tkinter is Python's standard GUI (Graphical User Interface) package.
● It is a thin object-oriented layer on top of the Tk GUI toolkit.
● Tk means toolkit
● Tkinter is included with standard installs of Python, So you need not to use pip install
tkinter.

Widgets: Label, Button, Entry, RadioButton, text fields etc

Creating window

Example: Create a window with title “Hello NIET”


It will open up a separate window like this:

Setting size of window


Setting Widgets in the Window's Interior

Widgets are the elements in a GUI application, like buttons, labels, and text boxes. To place
widgets inside a window, we use geometry managers like pack(), grid(), and place().
Change font of the text
Change label color
● Use label.config
● fg for foreground color
● bg for background color
Pack options

pack() also has padding options:

● padx, which pads externally along the x axis.


● pady, which pads externally along the y axis.
● ipadx, which pads internally(within) along the x axis.
● ipady, which pads internally(within) along the y axis.
Side attribute in pack()
Button Widget
● Use Button class to create button objects.
Change Button Text on click

Numeric Widgets
● Numeric widgets allow users to input numbers.
● Common numeric widgets include Scale and Spinbox.
Example: Scale Widget
Example: Spinbox Widget

Boolean Widgets
Boolean widgets represent boolean values (True/False).
The most common boolean widgets are Checkbutton and Radiobutton.
Example: Checkbutton Widget

Example: Radiobutton Widget


Selection Widgets
Selection widgets allow users to select from a list of options.
Common selection widgets include Listbox and Combobox.

Example: Listbox Widget


Example: combobox Widget
String Widgets
String widgets allow users to input and display text.
Common string widgets include Entry and Label.

Example: Entry Widget


Grid
● grid is used to place widgets.
Example: Create a login sample page using grid.
Date Picker
Tkinter does not have a built-in date picker, but you can use the tkcalendar module to add one.

Example: Date Picker


First, install the tkcalendar module:
Color Picker
● Tkinter provides a built-in color picker dialog through the colorchooser module.

Example: Color Picker


Container Widgets
● Container widgets are used to hold other widgets.
● Common container widgets include Frame and PanedWindow.

Example: Frame Widget


Canvas Widget
The Canvas widget is used for drawing shapes, such as lines, circles, and rectangles.
Example to add two numbers
Project: Arithmetic calculator

You might also like