EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Tkinter place

Secondary Sidebar
Tkinter Tutorial
  • Tkinter
    • Python Tkinter
    • Tkinter Widgets
    • Tkinter background image
    • Tkinter button color
    • Tkinter place
    • Python Tkinter Button
    • Python Tkinter Canvas
    • Tkinter Frame
    • Tkinter LabelFrame
    • Python Tkinter Label
    • Tkinter Text
    • Tkinter Scrollbar
    • Tkinter Listbox
    • Tkinter Spinbox
    • Tkinter Checkbutton
    • Tkinter Menu
    • Tkinter Menubutton
    • Tkinter OptionMenu
    • Tkinter Messagebox
    • Tkinter Grid
    • Tkinter Pack
    • Tkinter Scale
    • Tkinter Table
    • Python Tkinter Entry
    • Tkinter after
    • Tkinter Colors
    • Tkinter Font
    • Tkinter PhotoImage
    • Tkinter TreeView
    • Tkinter Notebook
    • Tkinter Combobox
    • Tkinter Bind
    • Tkinter Icon
    • Tkinter Window Size
    • Tkinter Color Chart
    • Tkinter Slider
    • Tkinter Calculator
    • Tkinter geometry
    • Tkinter image
    • Tkinter input box
    • Tkinter mainloop
Home Software Development Software Development Tutorials Tkinter Tutorial Tkinter place

Tkinter place

Introduction to Tkinter place

Tkinter is used to create GUI in python, and it is the most commonly used library we have. By the use of it, we can create a GUI very easily and very fast. As the name suggests, it is used to specified someplace for the GUI component. Tkinter has many layout manager places is one of them. By the use of place, we can assign the size or position of the window. It is a geometry manager position widget we have in the Tkinter module.

Syntax

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

To make use of the place, we first need to import the Tkinter package into our program. We can use this to place buttons, labels, and many other GUI stuff to place them properly into the window. Now we will see the syntax to use this in our program;

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,064 ratings)

Example:

place(relx = val, rely = val, anchor = VAL)

In order to use this, we need to pass three parameters inside it. Which are named as relax, rely and anchor to place our widgets on the screen. We can call this method on any widgets we have available in the Tkinter module to develop our GUI for users. Let’s see one practice syntax to understand it better see below;

button1.place(relx =1, rely =1, anchor = N)

Here we call this method on the button widget and place the variables here 1,1, and N to relax, rely, and anchor, respectively.

How does the place method work in Tkinter?

As of now, we know that we use a place to place our widgets on the window. Which can be relative or absolute position on the window. We have three different layouts available in Tkinter are named as place, pack, and grid. These all three are based on different positioning. The place is based on absolute positioning; we will discuss absolute positioning in details see below;

Absolute positioning: This can be termed as fixed positioning, not relative. Suppose we have some different sizes of our window that encapsulate all our widgets in the right position in the past. But suppose we want to resize our window in the future, so the widgets will not be moving from their position irrespective of the window size. Also, the size of every widget will be in pixels. This means the look and feel of the application will be different from one platform to another one, as we see in many web applications where it looks different on chrome, firefox, and other browsers. The same is the case is here the GUI will be different on Mac, Linux, and windows, and many more. By using this, we can place our widgets on the window like labels, buttons, text, etc. Now we will see one example of how to use this and how it internally works to place the widgets on the window. We will see one simple example that will be under stable by the beginners as well see below;

Example:

from tkinter import *
parent = Tk()
parent.geometry("150x150")
button1 = Button(parent, text = "Hi I am button! Click me to start!!")
button1.place(relx = 1, relay =1, anchor = N)
mainloop()

In the above code lines, we create one GUI for users and display them one button. The first thing to get started with the place is to import the Tkinter module into the program to use all its methods and widgets properly; it will help us to create the GUI very faster and in the easy way possible. After the import has been done, we are creating one window here by using the Tkinter object and assign a size for the window, which is here as 150pixels. After that, we are creating one button by using the Button widgets available and passing parameters inside it. The one parameter that it takes is the parent object, i.e., Tkinter here. After that, we are assigning text to the button that will be displayed on the button. Also, we can call or trigger some events by clicking the button that is called events. Immediately after this, we call the place method here to give the position to this button on the window by initializing all the variables. In the end, we have called mainloop() to initialize the window.

Constructor

As we have already seen, this takes different parameters like height, anchor, relx, rely, and so on. We will discuss these parameters more in detail see below;

Here is the syntax for its constructor see below;

place(relx = val, rely = val, anchor = VAL)
  • height: By using this parameter, we can specify the height in pixels.
  • width: By using this parameter, we can specify the width in pixels.
  • anchor: By using this parameter, we can specify the original position of the GUI component, or we can say widget on the window. It comes up with so many different options for positioning the widget like S, W, E, N, SW, WE, EN. This position will indicate the corners, and it also has one default position that is NW.
  • relax: This parameter represents the horizontal offset between 0.0. to 1.0.
  • relay: This parameter represents the vertical offset between 0.0. to 1.0.
  • Y: This is the vertical offset that comes in pixels.
  • X: This is the horizontal offset that comes in pixels.

Methods

We have some of the method available which can be used with the place which is as follows see below;

  • pack (): This method is used to format or positioning our GUI widgets in vertical and horizontal boxes.
  • grid (): As the name suggests, it can handle the list data and is defined as the method that manages to show the widgets in two-dimensional ways.

Example of Tkinter place

In this example, we are creating two labels one will show at the center one other one will show at the upper left corner of the window.

Example:

from tkinter import *
parent = Tk()
master.geometry("300x300")
#label one creating
l = Label(parent, text = "This is label one !!")
l.place(relx = 1, rely = 1, anchor = NW)
#label two creating
l = Label(parent, text = "This is label two !!")
l.place(relx = 1, rely = 1, anchor = CENTER)
mainloop()

Output :

Tkinter place output

Conclusion

By using this place method, we can place our widgets on the GUI window. Bypassing various parameters to its constructor, we can place them at right, left top, and bottom. Also, we can place them at the corner of the window as well. But to use this, we would require the Tkinter module to be imported into our application.

Recommended Articles

This is a guide to Tkinter place. Here we discuss How does the place method work in Tkinter along with the Constructor, Methods, and Example. You may also have a look at the following articles to learn more –

  1. Tkinter Bind
  2. Tkinter Combobox
  3. Tkinter after
  4. Tkinter Grid
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

Special Offer - All in One Software Development Bundle (600+ Courses, 50+ projects) Learn More