如何在 tkinter ~ python 中放置在网格中的两个小部件之间添加空间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39555194/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add space between two widgets placed in grid in tkinter ~ python?
提问by Vimo
a. Have placed a widget in the row 0 in the grid as shown below.
一种。在网格的第 0 行放置了一个小部件,如下所示。
self.a_button = Button(root, text="A Button")
self.a_button.grid(row=0, column=1)
b. And tried placing another widget in row 2 inside the grid.
湾 并尝试在网格内的第 2 行放置另一个小部件。
self.b_button = Button(root, text="B Button")
self.b_button.grid(row=2, column=1)
But when I run the program, I don't see any space between the widgets, rather its stacked once after the other.
但是当我运行程序时,我没有看到小部件之间有任何空间,而是一个接一个地堆叠在一起。
So, how do I program to allow space between two widgets placed in different rows? Share your comments !!
那么,我如何编程以允许放置在不同行中的两个小部件之间有空间?分享您的意见!!
回答by Arctoran
When you pack the widget you can use
当您打包小部件时,您可以使用
self.a_button = Button(root, text="A Button")
self.a_button.grid(row=0, column=1, padx=10, pady=10)
Using padx and pady you can add padding to the outer side of the button and alternatively if you want to increase the size of the button you can add inner padding using ipadx and ipady.
使用 padx 和 pady,您可以向按钮的外侧添加填充,或者如果您想增加按钮的大小,您可以使用 ipadx 和 ipady 添加内部填充。
If you want more on the Grid function you can view all the options and uses here.
如果您想了解更多关于网格功能的信息,您可以在此处查看所有选项和用途。