2
from tkinter import *
from tkinter import ttk

_root = Tk()

_F_Cassa = PanedWindow(_root, orient = HORIZONTAL)
_F_Cassa.pack(fill = BOTH, expand = True )

_F_Right = Frame(_F_Cassa)
_F_Left = Frame(_F_Cassa)


_F_Cassa.add(_F_Left)
_F_Cassa.add(_F_Right)

_L_NomeS = Button(_F_Left, text = "Sinistra")
_L_NomeS.grid(row = 0, column = 0)


_L_NomeD = Button(_F_Right, text = "Destra")
_L_NomeD.grid(row = 0, column = 0)


_root.mainloop()

I'm trying to build an app that consists in a PanedWindow widget that holds 2 frames (Left and Right) that are then populated with "standard" widgets like buttons, labels etc...the problem is that I get this result:

enter image description here

but what I want is something like this:

enter image description here

I tried to add width and height to the frames, but it didn't worked.

Just so everything is clear: i'm not using widgets from the ttk module, just the normal tk.

1 Answer 1

3

Indeed, you can not change the dimensions of the Frame instances directly as you tried because both frames are PaneWindow child widgets.

To resolve your problem, you need to investigate paneconfig() method like this:

_F_Cassa.paneconfig(_F_Left, width = 120, height = 400, sticky = E+W+S+N)
_F_Cassa.paneconfig(_F_Right, width =  200, height = 400, sticky = E+W+S+N)

Full program:

from tkinter import *

_root = Tk()
_root.title("BEGUERADJ PaneWindow")

_F_Cassa = PanedWindow(_root, orient = HORIZONTAL)
_F_Cassa.pack(fill = BOTH, expand = True )
"""
Every column and row has a "weight" grid option associated with it, 
which tells it how much it should grow if there is extra room in the 
_F_Cassa to fill. By default, the weight of each column or row is 0, 
meaning don't expand to fill space.
"""
_F_Cassa.grid_rowconfigure(0, weight = 1)
_F_Cassa.grid_columnconfigure(0, weight = 1)

# I set background colors just to highlight the results
_F_Right = Frame(_F_Cassa, bg = "blue")
_F_Left = Frame(_F_Cassa, bg = "yellow")    

_F_Cassa.add(_F_Left)
_F_Cassa.add(_F_Right)

_F_Right.grid(row = 0, column = 1)
_F_Left.grid(row = 0, column = 0)

_L_NomeS = Button(_F_Left, text = "Sinistra")
_L_NomeS.grid(row = 0, column = 0)


_L_NomeD = Button(_F_Right, text = "Destra")
_L_NomeD.grid(row = 0, column = 0)   

# Resize frame widgets:
_F_Cassa.paneconfig(_F_Left, width = 120, height = 400, sticky = E+W+S+N)
_F_Cassa.paneconfig(_F_Right, width =  200, height = 400, sticky = E+W+S+N)


_root.mainloop()

Demo

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Ok it works, but why you say _F_Cassa.grid_rowconfigure(0, weight = 1) _F_Cassa.grid_columnconfigure(0, weight = 1) since Im already using pack on the paned window?
Yes, always use grid_rowconfigure() and grid_columnconfigure() IF you use later sticky for child widgets for the reason I explained as a long comment in my code. Does this contradict pack() layout manager? No, not at all. We have the full right to mix them, and this context is a right one because pack() fills _F_Cassa within the _root while grid() manager (and thus grid_rowconfigure() and grid_columnconfigure()) is used to manage the widgets inside/relatively to _F_Cassa. @Steve

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.