如何在 tkinter ~ python 中放置在网格中的两个小部件之间添加空间? [英] How to add space between two widgets placed in grid in tkinter ~ python?

查看:51
本文介绍了如何在 tkinter ~ python 中放置在网格中的两个小部件之间添加空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个.在网格的第 0 行放置了一个小部件,如下所示.

a. Have placed a widget in the row 0 in the grid as shown below.

self.a_button = Button(root, text="A Button")
self.a_button.grid(row=0, column=1)

B.并尝试在网格内的第 2 行放置另一个小部件.

b. And tried placing another widget in row 2 inside the grid.

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 !!

推荐答案

打包小部件就可以使用

self.a_button = Button(root, text="A Button") 
self.a_button.grid(row=0, column=1, padx=10, pady=10)

使用 padx 和 pady,您可以在按钮的外侧添加填充,或者如果您想增加按钮的大小,您可以使用 ipadx 和 ipady 添加内部填充.

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.

如果您想了解更多关于网格功能的信息,您可以查看所有选项并使用此处.

If you want more on the Grid function you can view all the options and uses here.

这篇关于如何在 tkinter ~ python 中放置在网格中的两个小部件之间添加空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆