vagnerPG
vagnerPG

Reputation: 43

What is this "extra padding" from the Entry widget from Tkinter?

Take this simple code:

import os
import tkinter as tk

root_window = tk.Tk()
root_window.geometry("200x200")

root_window.columnconfigure(0, weight=1)
root_window.columnconfigure(1, weight=1)
root_window.rowconfigure(0, weight=1)

foo = tk.Canvas(root_window, bg="grey", width=10, height=10)
bar = tk.Canvas(root_window, bg="light grey", width=10, height=10)

foo.grid(row=0, column=0, sticky="nsew")
bar.grid(row=0, column=1, sticky="nsew")

root_window.mainloop()

The resulting behavior is completely normal and expected:

screen gets divided into two equal sides

but if you change foo to an Entry widget (and remove the sticky="nsew" from grid):

foo = tk.Entry(root_window, width=10) # same width
foo.grid(row=0, column=0)

Then the entry widget seems to get some sort of 'padding', on both sides, out of nowhere:

entry widget appear to have extra space

I thought that it had a default padx, but even after trying padx=(0,0), nothing happened.

It also only happens on its sides(left and right), top and bottom work normally.

Even if you use sticky="nsew" on the grid method, the result also has the extra space.

Is there something I am missing? Can I remove this "extra padding"?

PS: I tried using the syntax to make the images be on the post, instead of a link to them, but couldn't get it to work.

Upvotes: 1

Views: 65

Answers (1)

acw1668
acw1668

Reputation: 46669

The extra padding in the last image is not from the entry widget, but from the canvas widget on the right. It can be removed by setting highlightthickness=0 when creating it:

bar = tk.Canvas(root_window, bg="light grey", width=10, height=10, highlightthickness=0)

Result:

enter image description here

Upvotes: 0

Related Questions