i have been trying to create this layout for a game Im creating using packs anchor and side shown below.
The black and blue shapes are canvases and orange is a frame
Can anyone help figure out the correct way to pack them
i have been trying to create this layout for a game Im creating using packs anchor and side shown below.
The black and blue shapes are canvases and orange is a frame
Can anyone help figure out the correct way to pack them
pack
works by allocating one edge of the unused space in a window. In this case, you want to do something like the following:
In the following example I assume you want the blue area to grown and shrink when the window is resized. It doesn't have to be that way, it all depends on how you use the fill
and expand
attributes. The key takeaway here is that you use pack by filling the unused space one side at a time.
import tkinter as tk
root = tk.Tk()
black = tk.Canvas(root, background="black", width=200, height=100, bd=0, highlightthickness=0)
blue = tk.Canvas(root, background="blue", width=600, height=400, bd=0, highlightthickness=0)
orange = tk.Frame(root, background="orange", height=100, width=200, bd=0, highlightthickness=0)
black.pack(side="bottom", fill="x")
orange.pack(side="right", fill="y")
blue.pack(side="left", fill="both", expand=True)
root.mainloop()
For another explanation of how the packer works, with images, see this answer
For an authoritative description of how the packer works, see The Packer Algorithm in the tcl/tk manual pages for pack