YAsh rAj
YAsh rAj

Reputation: 87

Adding a gap between widgets

enter image description here

How do I get a gap in between the two buttons, generate and clear?

Upvotes: 0

Views: 7261

Answers (1)

Mike - SMT
Mike - SMT

Reputation: 15236

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. If you want to add space between all 3 pady = (5,5) or pady = 5.

There are 2 ways you can provide a number/numbers to your padx or 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.

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:

enter image description here

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:

enter image description here

Upvotes: 7

Related Questions