I'm trying to build a simple GUI in Tkinter and I'm having trouble with placing a frame and a canvas beside each other. The canvas seems to take up more space than the width and height that have been specified.
Example code:
root = tk.Tk()
parent = tk.Frame(root)
parent.grid()
parent.master.geometry('400x400')
canvas = tk.Canvas(parent, width=200, height=400, relief='raised', borderwidth=5)
canvas.grid(row=0, column=0, sticky='nsew')
frame = tk.Frame(parent, width=200, height=400, relief='raised', borderwidth=5)
frame.grid(row=0, column=1, sticky='nsew')
parent.mainloop()
This gives this result:
You can see that the canvas has pushed the frame outside the window
However, when its just the frame, the frame fits nicely within the window:
When it's just the canvas the canvas pushes outside the window:
What is causing this difference in sizing and how do I handle it? Is there a proper way to set the size of a canvas?