[Tkinter] Text Button - How Do I Reduce The Margin? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [Tkinter] Text Button - How Do I Reduce The Margin? (/thread-26250.html) |
Text Button - How Do I Reduce The Margin? - vman44 - Apr-25-2020 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: https://effbot.org/tkinterbook/button.htm https://www.tutorialspoint.com/python/tk_button.htm https://pythonexamples.org/python-tkinter-button-change-font/ RE: Text Button - How Do I Reduce The Margin? - Larz60+ - Apr-25-2020 please show your code. RE: Text Button - How Do I Reduce The Margin? - Roshan - Apr-25-2020 use width = 10use this where is creating button. choose numeric value as u need. i hope this help. RE: Text Button - How Do I Reduce The Margin? - deanhystad - Apr-25-2020 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) tk.mainloop() RE: Text Button - How Do I Reduce The Margin? - vman44 - Apr-25-2020 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. RE: Text Button - How Do I Reduce The Margin? - vman44 - Apr-27-2020 It looks like I'm able to get the width thing to work. Thanks, everyone. RE: Text Button - How Do I Reduce The Margin? - Larz60+ - Apr-27-2020 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 |