[英]Adding a gap between widgets
If you are only looking to have padding between the 2 buttons you can use pady = (0,5)
in your grid()
manager for your Generate button. 如果您只希望在2个按钮之间使用填充,则可以在
grid()
管理器中为“生成”按钮使用pady = (0,5)
。 If you want to add space between all 3 pady = (5,5)
or pady = 5
. 如果要在3个
pady = (5,5)
或pady = 5
之间添加空格。
There are 2 ways you can provide a number/numbers to your padx
or pady
. 您可以通过两种方式为
padx
或pady
提供一个数字。 You can use just a number like pady = 5
and this would do both the top and bottom padding but if you want to specifically pad just one side you can provide a tuple like this pady = (0,5)
and this would just pad the bottom of the widget. 您可以只使用
pady = 5
类的数字,这将同时进行顶部和底部填充,但是如果您只想仅填充一侧,则可以提供一个类似于pady = (0,5)
的元组,这将仅填充小部件的底部。
Here is an example: 这是一个例子:
import tkinter as tk
root = tk.Tk()
tk.Entry(root, width = 25).grid(row=0, column=0)
tk.Button(root, text = "Generate").grid(row=1, column=0, pady = (5,5))
tk.Button(root, text = "clear").grid(row=2, column=0)
root.mainloop()
Results: 结果:
And here is an example for just space between the buttons: 以下是按钮之间仅留空格的示例:
import tkinter as tk
root = tk.Tk()
tk.Entry(root, width = 25).grid(row=0, column=0)
tk.Button(root, text = "Generate").grid(row=1, column=0, pady = (0,5))
tk.Button(root, text = "clear").grid(row=2, column=0)
root.mainloop()
Results: 结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.