问题
I'm using python2 on Windows. When I run the followig code, I get a gap between the two canvas (see picture below), although there is no padding specified when I grid them. Is there any possibility to remove this?
import Tkinter as tk
import ttk
class App(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.c1 = tk.Canvas(master=self, background='white', borderwidth=0,
relief=tk.FLAT)
self.c2 = tk.Canvas(master=self, background='white', borderwidth=0,
relief=tk.FLAT)
self.c1.grid(row=0, column=0, sticky=tk.NSEW)
self.c2.grid(row=1, column=0, sticky=tk.NSEW)
self.mainloop()
App()
Thanks for help!
回答1:
You need to set highlightthickness
to zero as well.
self.c1 = tk.Canvas(..., highlightthickness=0)
From the canvas page of effbot highlightthickness
explained as:
The width of the highlight border. The default is system specific (usually one or two pixels). (highlightThickness/HighlightThickness)
来源:https://stackoverflow.com/questions/42025015/remove-automatic-gap-between-gridded-python-tkinter-widgets