Choose which part of the panel to resize

Viewed 35

I'm trying to figure out how to choose which part of the panel changes sizes when changing the size of the window. The way it goes right now is that every time I change the size of the window, it's the panel on the right or the one on the bottom the ones that change while the one on the left and the one on the top remain the same size. I want it to be the other way around. I want it to be so that the one that changes size is the one on the left, not the one on the right. I've tried changing the different parameters for pack but it affects the whole panel, not just one side.

This is the code I'm using as a reference.

from tkinter import *

root = Tk()
root.title("Hello World!")
root.geometry("400x400")


panel_1 = PanedWindow(bd=4, relief="raised", bg="red")
panel_1.pack(fill=BOTH, expand=1)

left_label = Label(panel_1, text="Left Panel")
panel_1.add(left_label)


panel_2 = PanedWindow(panel_1, orient=VERTICAL, bd=4, relief="raised", bg="blue")
panel_1.add(panel_2)

top = Label(panel_2, text="Top Panel")
panel_2.add(top)

bottom = Label(panel_2, text="Bottm Panel")
panel_2.add(bottom)

root.mainloop()
1 Answers

Here is the modified code following @jasonharper advice.


from tkinter import *

root = Tk()
root.title("Hello World!")
root.geometry("400x400")


panel_1 = PanedWindow(bd=4, relief="raised", bg="red")
panel_1.pack(fill=BOTH, expand=1)

left_label = Label(panel_1, text="Left Panel")
panel_1.add(left_label, stretch="always")


panel_2 = PanedWindow(panel_1, orient=VERTICAL, bd=4, relief="raised", bg="blue")
panel_1.add(panel_2, stretch="never")

top = Label(panel_2, text="Top Panel")
panel_2.add(top)

bottom = Label(panel_2, text="Bottm Panel")
panel_2.add(bottom)

root.mainloop()

Related