Python Forum
[Tkinter] Text Button - How Do I Reduce The Margin?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Text Button - How Do I Reduce The Margin?
My Python script uses Tkinter.
I'm running Python 3.7.

The script creates a large # of text buttons
next to each other.

How do I reduce the margin between the text &
the edge of the button?

Every time I change the font size, it automatically
changes the button size, while keeping the margins.

I've looked at the following, but they didn't help:
please show your code.
width = 10
use this where is creating button.

choose numeric value as u need.

i hope this help.
If you used themed tk buttons (ttk.Button) you can set padding. You can also set width if the the top/bottom margins look good but the button is too wide.
import tkinter as tk
import tkinter.ttk as ttk

root = tk.Tk()

ttk.Button(root, text='Text').grid(row=0, column=0)
ttk.Button(root, text='Text', padding=5).grid(row=1, column=0)
ttk.Button(root, text='Text', padding=-5).grid(row=2, column=0)
ttk.Button(root, text='Text', width=4).grid(row=3, column=0)

The width option doesn't work.

Here's my code:
b = Button(tkt, height=1, width=1, text='J', command=tkt.destroy, bg='#DEDEFF', fg="green")

Earlier in my script, I put:
# define font
myFont = font.Font(family='Helvetica', size=20, weight='bold')

The problem is that when I change the font size in myFont,
it keeps adjusting all the margins in the Button function.

I'll try the "grid" option later today.

Thanks, everyone, for the tips.

Actually, the width margins are ok.
It's the height margins which are an issue.

Using the grid didn't work.
It looks like I'm able to get the width thing to work.

Thanks, everyone.
you need to set your padding.
padding internal to widget is padx, pady
padding outside of widget is controlled by ipadx, ipady in a grid or pack command

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Make my button text update? Skata100 1 490 Aug-07-2021, 05:37 AM
Last Post: deanhystad
  Tkinter reduce OptionMenu height euras 2 725 May-25-2021, 09:14 PM
Last Post: euras
  Updating button text based upon different variable values knoxvilles_joker 0 763 Apr-18-2021, 04:13 AM
Last Post: knoxvilles_joker
  tkinter | Button color text on Click Maryan 2 1,393 Oct-09-2020, 08:56 PM
Last Post: Maryan
  How to make button text bold in Tkinter? scratchmyhead 2 3,465 May-16-2020, 02:53 AM
Last Post: scratchmyhead
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 2,805 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  Text after push button chano 13 2,870 Jul-05-2019, 03:10 PM
Last Post: Yoriz
  [Tkinter] how do i add a margin to a Listbox DT2000 27 11,135 May-14-2019, 04:07 AM
Last Post: DT2000
  Can't change the colour of Tk button text Pilover 4 8,253 Feb-27-2019, 09:02 PM
Last Post: Pilover
  Set input text from button gio123 1 1,910 Mar-01-2018, 10:28 AM
Last Post: gio123

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020