简体   繁体   English

当我尝试更换稻田时,为什么我的 Tkinter 按钮消失了?

[英]Why does my Tkinter Button disappear when i try to change the pady?

I tried to center the Button and set it to the Bottom but when i set the pady to 300, the Button disappear.我试图将按钮居中并将其设置为底部,但是当我将pady设置为 300 时,按钮消失了。 So here my Question: Why does that happen and how do i fix it?所以我的问题是:为什么会发生这种情况,我该如何解决?

Here my Code:这是我的代码:

import tkinter as tk


root = tk.Tk()
root.title("Test")
root.minsize(1000, 600)
root.maxsize(1000, 600)
root.config(bg = "#524D4C")


frame = tk.LabelFrame(root, padx=20, pady=20)

rolls = tk.Button(frame, width=20, height=2)
sides = tk.Button(frame, width=20, height=2)


frame.pack(pady=300)
rolls.grid(row=0, column=0)
sides.grid(row=0, column=2)

root.mainloop()

Why does my Tkinter Button disappear when i try to change the pady?当我尝试更换稻田时,为什么我的 Tkinter 按钮消失了?

It is because the padding applies to both the top and bottom of the frame.这是因为填充适用于框架的顶部和底部。 You've forced the window to be 600 pixels tall, and 300*2 is 600, so the widget must shrink down to a height of zero for it to fit.您已强制窗口高度为 600 像素,而 300*2 为 600,因此小部件必须缩小到零高度以适合它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM