0% found this document useful (0 votes)
66 views3 pages

Computer: Python Tkinter Geometry

Tkinter provides various widgets like Button, Canvas, Checkbutton, and Entry that can be used to build Python GUI applications. These widgets can be organized and placed on windows using geometry managers like pack(), grid(), and place(). Pack places widgets without strict positioning while place allows exact positioning by x and y coordinates. Geometry can also be set at the window level using methods like geometry().

Uploaded by

Jer Felysse
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
66 views3 pages

Computer: Python Tkinter Geometry

Tkinter provides various widgets like Button, Canvas, Checkbutton, and Entry that can be used to build Python GUI applications. These widgets can be organized and placed on windows using geometry managers like pack(), grid(), and place(). Pack places widgets without strict positioning while place allows exact positioning by x and y coordinates. Geometry can also be set at the window level using methods like geometry().

Uploaded by

Jer Felysse
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 3

Computer

Python Tkinter Geometry


Sources: Canvas

Developing desktop-based applications


with python Tkinter is not a complex task. An
empty Tkinter top-level window can be
created by using the following steps. 1. Button
- import the Tkinter module. is used to add various kinds of buttons
- Create the main application window. to the python application
- Add the widgets like labels, buttons,
frames, etc. to the window. 2. Canvas
- Call the main event loop so that the
is used to draw the canvas on the
actions can take place on the user's
window.
computer screen.
3. Checkbutton
Example:
1. # !/usr/bin/python3 is used to display the CheckButton on
2. from tkinter import * the window.
3. # creating the application
main window. 4. Entry
4. top = Tk()
5. # Entering the event main is used to display the single-line text
loop field to the user. It is commonly used to
6. top.mainloop() accept user values.
Output: 5. Frame

It can be defined as a container to


which, another widget can be added and
organized.

6. Label

is a text used to display some


message or information about the other
widgets.

7. ListBox

is used to display a list of options to


Tkinter Widgets the user.

There are various widgets like button, 8. Menubutton


canvas, checkbutton, entry, etc. that are used
is used to display the menu items to
to build the python GUI applications.
the user.
1
9. Menu 19. MassageBox

It is used to add menu items to the This module is used to display the
user. message-box in the desktop-based
applications.
10. Message

is used to display the message-box to


PYTHON TKINTER
the user. GEOMETRY
11. Radiobutton The Tkinter geometry specifies the
method by using which, the widgets are
It is different from a checkbutton. represented on display. The python Tkinter
provides the following geometry methods.
Here, the user is provided with various
options and the user can select only one - The pack() method
option among them. - The grid() method
- The place() method
12. Scale
PACK() METHOD
It is used to provide the slider to the
user. The pack() widget is used to organize
widget in the block. The positions widgets
13. Scrollbar
added to the python application using the
It provides the scrollbar to the user so pack() method can be controlled by using the
that the user can scroll the window up and various options specified in the method call.
down.
However, the controls are less and
14. Text widgets are generally added in the less
it is different from Entry because it organized manner.
provides a multi-line text field to the user so SYNTAX
that the user can write the text and edit the
text inside it. A list of possible options that can be
passed in pack() is given below.
15. Toplevel
- expand: If the expand is set to true, the
It is used to create a separate window
widget expands to fill any space.
container.
- Fill: By default, the fill is set to NONE.
16. Spinbox However, we can set it to X or Y to
It is an entry widget used to select determine whether the widget contains
from options of values. any extra space.
- size: it represents the side of the
17. PanedWindow
parent to which the widget is to be
It is like a container widget that placed on the window.
contains horizontal or vertical panes.
Example:
18. LabelFrame
1. # !/usr/bin/python3
is a container widget that acts as the 2. from tkinter import *
container 3. parent = Tk()
2
4. redbutton = Button(parent, text = "Red", indicating the fraction of the parent's
fg = "red") height and width.
5. redbutton.pack( side = LEFT) - relx, rely: It is represented as the float
6. greenbutton = Button(parent, text = between 0.0 and 1.0 that is the offset
"Black", fg = "black") in the horizontal and vertical direction.
7. greenbutton.pack( side = RIGHT ) - x, y: It refers to the horizontal and
8. bluebutton = Button(parent, text = vertical offset in the pixels.
"Blue", fg = "blue")
Example:
9. bluebutton.pack( side = TOP )
10. blackbutton = Button(parent, text = 1. # !/usr/bin/python3
"Green", fg = "red") 2. from tkinter import *
11. blackbutton.pack( side = BOTTOM) 3. top = Tk()
12. parent.mainloop() 4. top.geometry("400x250")
5. name = Label(top, text =
"Name").place(x = 30,y = 50)
6. email = Label(top, text =
"Email").place(x = 30, y = 90)
Output:
7. password = Label(top, text =
"Password").place(x = 30, y = 130)
8. e1 = Entry(top).place(x = 80, y = 50)
9. e2 = Entry(top).place(x = 80, y = 90)
10. e3 = Entry(top).place(x = 95, y = 130)
11. top.mainloop()

PLACE() METHOD Output:

The place() geometry manager


organizes the widgets to the specific x and y
coordinates.

SYNTAX

A list of possible options is given below.

- Anchor: It represents the exact


position of the widget within the
container. The default value (direction)
is NW (the upper left corner)
- bordermode: The default value of the
border type is INSIDE that refers to
ignore the parent's inside the border.
The other option is OUTSIDE.
- height, width: It refers to the height and
width in pixels.
- relheight, relwidth: It is represented as
the float between 0.0 and 1.0
3

You might also like