Is there a way to position a canvas in a window and have a frame around it?I found only how to position objects inside a canvas.
3 Answers
You can create a frame, then put your widgets in it:
f = tk.Frame(...)
c1 = tk.Canvas(f, ...)
c2 = tk.Canvas(f, ...)
c1.pack(side="left", fill="both", expand=True)
c2.pack(side="right", fill="both", expand=True)
The above will give you two side-by-side canvases inside a single frame. They will grow and shrink as you resize the containing window.
Comments
Like fortyTwo102 mentioned, the place function will allow you to specify exactly where the canvas is. I thought I'd provide some more examples:
# in the center
canvas.place(relx=0.5, rely=0.5, anchor=CENTER)
# in the bottom right corner
canvas.place(relx=1.0, rely=1.0, anchor=SE)
# in the bottom left corner
canvas.place(relx=0.0, rely=1.0, anchor=SW)
# 30 pixels from the left, 50 from the top
canvas.place(x=30, y=50)
Source (and more helpful info): https://www.tutorialspoint.com/python/tk_place.htm
Frameand use the frame object as theCanvas's master. What's the problem?grid()orpack()as your geometry manager?canvas1.pack(side=LEFT)andcanvas2.pack(side=RIGHT). I'll be able to give a more detailed answer later.