Remove automatic gap between gridded python Tkinter widgets

柔情痞子 提交于 2020-01-11 12:50:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!