abhishek006
abhishek006
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:
Outcome:
Tkinter is the standard GUI library for Python, allowing developers to create graphical user
interfaces for their applications quickly and easily. It is built on the Tk GUI toolkit and
provides an object-oriented interface to work with the components of this toolkit.
When Python is combined with Tkinter, it provides a fast and easy way to create desktop
applications. Tkinter abstracts the complexities of dealing with graphical elements, making it
easier for developers to design and interact with the GUI of their applications.
Creating a GUI application using Tkinter follows a few simple steps. Here’s a general
outline:
This creates a window that is essentially empty, awaiting the addition of widgets.
Widgets in Tkinter are the building blocks of your GUI application. They allow you to create
interactive elements for users to interact with. Below are descriptions of the various Tkinter
widgets:
1. Button
The Button widget creates a clickable button.
2. Canvas
The Canvas widget is used for drawing shapes like lines, ovals, and rectangles.
3. Checkbutton
The Checkbutton widget allows the user to select one or more options, typically
displayed as checkboxes.
4. Entry
The Entry widget creates a text box where users can enter a single line of text.
5. Frame
A Frame widget acts as a container for other widgets, useful for organizing your
layout.
6. Label
The Label widget is used to display text or images.
7. Listbox
The Listbox widget creates a list of options for the user to choose from.
8. Menubutton
The Menubutton widget creates a button that displays a menu when clicked.
9. Menu
The Menu widget contains a list of commands that can be added to a Menubutton.
10. Message
The Message widget displays multiline text for the user.
11. Radiobutton
A Radiobutton widget displays a set of options, where only one can be
selected at a time.
12. Scale
The Scale widget is a slider that lets the user select a value within a given range.
13. Scrollbar
The Scrollbar widget is used to add scrolling functionality to other widgets like
Listbox or Text.
14. Text
The Text widget allows the user to enter multiple lines of text.
15. Toplevel
The Toplevel widget creates a separate window that can be used for additional
content.
16. Spinbox
A Spinbox widget is a type of Entry widget that lets the user select from a
fixed list of values.
Widgets in Tkinter come with several standard attributes that control their appearance and
behavior. Some of these attributes include:
• Dimensions: You can set the height and width of widgets (e.g., width, height).
• Colors: Widgets can have background and foreground colors (e.g., bg, fg).
• Fonts: The font of text in widgets can be customized using attributes like font.
• Anchors: You can align text or other elements inside a widget using anchor points like n, s, e,
w (north, south, east, west).
• Relief Styles: These control the border appearance (e.g., flat, raised, sunken, groove).
• Bitmaps: Widgets can display bitmaps, which are small images.
• Cursors: The appearance of the mouse cursor can be customized (e.g., arrow, hand2).
Geometry Management
Tkinter provides three main geometry managers for organizing widgets inside a container:
1. pack() Method
This method organizes widgets in blocks and places them in the parent container. You
can control the side of the window (e.g., top, left, right).
button = tkinter.Button(top, text="Click Me")
button.pack(side="top")
2. grid() Method
The grid() method arranges widgets in a table-like structure. You specify the row
and column for each widget.
3. place() Method
The place() method allows for absolute positioning of widgets, where you specify
the x and y coordinates.
These geometry managers help ensure that your application’s interface is well-organized
organized and
visually appealing. By choosing the right manager, you can fine
fine-tune
tune your layout to meet
specific design requirements.
Program:
Conclusion: Thus we Creating GUI with python containing widgets such as labels, textbox,
radio, checkboxes and custom dialog boxes
R1 R2 R3
TOTAL
DOP DOS ATTENDENCE CONDUCTION VIVA 10 SIGNATURE
MARKS
2 MARKS 4 MARKS 4 MARKS