0

i have been trying to create this layout for a game Im creating using packs anchor and side shown below.

enter image description here

The black and blue shapes are canvases and orange is a frame

Can anyone help figure out the correct way to pack them

toyota Supra
  • 3,181
  • 4
  • 15
  • 19

1 Answers1

0

pack works by allocating one edge of the unused space in a window. In this case, you want to do something like the following:

  1. with the black frame, pack it along the bottom and have it fill in the x direction. This will fill up the bottom of the window.
  2. pack the orange frame on the right, which will be the right side of the unused space above the black frame. Have it fill in the y direction
  3. pack the blue frame to the left, and have it fill in both directions and also expand. This will fill up all of the space to the left of the orange frame, and above the black frame.

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()

screenshot

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

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685