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 normaly.
even if you use sticky="nsew"
on the grid method, the result also has the extra space.
Is there somthing I am missing? Can I remove this “extra padding”?
PS: I tried using the sintax to make the images be on the post, instead of a link to them, but couldn’t get it to work.