为什么我不能在tk中放置按钮。框架?



所以我试图制作一个tk.Frame程序,但遇到了一个问题。我试着把一个按钮放在一个精确的坐标上,但它不会出现。以下是该程序的一个片段:

class Login(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
button1 = Button(self, text="Login",padx=50,command=chech,background="grey",foreground="white")
button2 = Button(self, text="SQLREG",padx=50,background="grey",foreground="white",command=lambda: controller.show_frame("Register"))
button1.place(relx=228, rely=70)
button2.place(relx=63, rely=70)

我该怎么办?谢谢你的帮助。

您还没有为帧指定大小,所以它只有一个像素高和一个像素宽。您将按钮放置在x方向上的宽度为228倍,在y方向上的高度为63倍,因此它将不可见。

至于修复方法,很难说你不知道自己到底在做什么。我个人的建议是不要使用place。当您使用packgrid时,tkinter将能够使框架足够大,以容纳其所有子框架。如果您使用逻辑布局而不是固定布局来设计GUI,它将对屏幕分辨率、字体大小和窗口大小的变化做出更大的响应。

最新更新