Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the place layout Manager of Tkinter

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how to use Tkinter's place layout manager". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use Tkinter's place layout manager.

The place layout manager is the third type of layout manager supported by Tkinter, which allows programmers to specify the location and size of controls directly. For example, the following code:

From tkinter import * root = Tk () # absolute position Button (root,text= "absolute coordinate placement 1") .place (x = 20, y = 10, width=150, height=50) Button (root,text= "absolute coordinate placement 2") .place (x = 20, y = 80, width=150, height=50) root.mainloop ()

The following picture is generated by specifying the absolute coordinates, width, and height of the two buttons:

Readers who try to drag the bounded and lower boundaries of the window will know that no matter how the window is resized, the size and position of the two buttons will not change:

You can also position the control according to relative coordinates, such as the following code:

From tkinter import * root = Tk () Button (root,text= "relative coordinate placement 1") .place (relx=0.2, rely=0.2, relwidth=0.6, relheight=0.2) Button (root,text= "relative coordinate placement 2") .place (relx=0.2, rely=0.6, relwidth=0.6, relheight=0.2) root.mainloop ()

The difference between absolute coordinates and absolute coordinates is that each attribute is preceded by a rel prefix. A numeric value means the relative value of the width or height of the window. For example, the position of the window width 20% when relx=0.2 starts from the beginning of the meaning button, and so on. After the execution of this code, the following screen is generated:

If the reader drags the boundary of the window to expand the size of the window, the size and position of the space will also change, but the proportion of the position will remain the same in both horizontal and vertical directions.

Although the place layout manager looks simple, when there are more controls, the calculation and maintenance of coordinates will become very complex. For this reason, few Tkinter applications use this type of layout manager.

But it is up to the user to safely control the location and size of the control, which can be used as a basis if we want to define our own layout.

At this point, I believe you have a deeper understanding of "how to use Tkinter's place layout manager". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report