相当于 tkinter 中的 Qt.setGeometry()

Equalivent of Qt.setGeometry() in tkinter

tkinter中PyQt的equal函数是什么setGeometry()?或者有没有这样的功能?我搜索了一下但找不到,所有示例看起来都像 tkinter 在特定小部件上工作,我们可以设置宽度-高度。

EDIT:

The setGeometry() does two things. It locates the window on the screen and sets its size. The first two parameters are the x and y positions of the window. The third is the width and the fourth is the height of the window.

tkinter 拥有的最接近的东西可能是 place 几何管理器。使用它您可以设置 x,y 坐标(绝对或相对)以及宽度和高度属性(也可以是绝对或相对)。

例如,要将标签放置在 100,100 处且宽度和高度为其父项的 50%,您可以执行如下操作:

import tkinter as tk
root =  tk.Tk()
label = tk.Label(root, text="Hello, world")
label.place(x=100, y=100, relwidth=.5, relheight=.5)
root.mainloop()

然而,地方很少是正确的选择。 Tkinter 非常聪明地为小部件选择合适的大小,并布置它们。在不知道您要解决的实际问题的情况下,很难给出好的建议,但几乎可以肯定,pack or grid 会更好。

您还可以通过 grid 几何管理器执行类似于 @BryanOakley 的回答:

from tkinter import *
root = Tk()

label = Label(root, bg='cyan')
label.grid(ipadx=100, ipady=50, padx=50, pady=50)

更新:请反馈您认为此答案无用的原因。