Python Tkinter Canvas' border overlap with window create by `create_window' Python Tkinter Canvas' border overlap with window create by `create_window' tkinter tkinter

Python Tkinter Canvas' border overlap with window create by `create_window'


Oddly, the canvas border is part of the drawing space, so anything drawn on the canvas has the potential to overlap the borders.

The solution that I use is to remove the border from the canvas, and then put the canvas inside a frame that has a border. Visually it looks the same, but because the visible border belongs to another widget it is impossible for items in the canvas to overlap it.


You can solve that problem by setting the state to be hidden and when it's needed to set it back to normal like this

import tkinter......canvas = tkinter.Canvas(self, width=100, height=100, bd=0, highlightthickness=0)canvas.pack()btn = tkinter.Button(text="Click me", command=print)win = canvas.create_window(10, 10, anchor=tkinter.NW, window=btn)canvas.itemconfigure(win, state=tkinter.HIDDEN)......