How to create a resizable window with sidebar and content area?

I am trying to do something quite standard in graphic design using Python and Tkinter, and I cannot figure it out. I am trying to do something like the following:

+------+----------------------+
|      |                      |
|      |                      |
|      |                      |
|      |                      |
|      |                      |
|      |                      |
|      |                      |
|      |                      |
|      |                      |
|      |                      |
|      |                      |
|      |                      |
|      |                      |
|      |                      |
+------+----------------------+

. , , . , , , , . , , - , y.

, , :

from Tkinter import *

root = Tk()

# sidebar
sidebar = Frame(root, width=200, bg='white', height=500, relief='sunken', borderwidth=2)
sidebar.pack(expand=True, fill='y', side='left', anchor='nw')

# main content area
mainarea = Frame(root, bg='#CCC', width=500, height=500)
mainarea.pack(expand=True, fill='both', side='right')

root.mainloop()

, :

improperly-resizing layout

? , , ? .

+4
1

TL; DR: fill="both" .

, , . expand=true , . fill "x" , , . "y", , , , fill="both".

"x", "y", , . : " ", , , fill=both, .

, , . , , , , , :

import Tkinter as tk

root = tk.Tk()

# sidebar
sidebar = tk.Frame(root, width=200, bg='white', height=500, relief='sunken', borderwidth=2)
sidebar.pack(expand=False, fill='both', side='left', anchor='nw')

# main content area
mainarea = tk.Frame(root, bg='#CCC', width=500, height=500)
mainarea.pack(expand=True, fill='both', side='right')

root.mainloop()

, , ​​ . , , .

import Tkinter as tk

root = tk.Tk()

# sidebar
sidebar = tk.Frame(root, width=200, bg='white', height=500, relief='sunken', borderwidth=2)
sidebar.pack(expand=True, fill='both', side='left', anchor='nw')

# main content area
mainarea = tk.Frame(root, bg='#CCC', width=500, height=500)
mainarea.pack(expand=True, fill='both', side='right')

root.mainloop()

- expand=true expand=False. , . true, , , true. , , , , . fill="both". fill , , ( ), , , .

  • expand:
  • : , , .
+4

Source: https://habr.com/ru/post/1530702/


All Articles