简体   繁体   中英

Remove automatic gap between gridded python Tkinter widgets

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!

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM