Python | PanedWindow Widget in Tkinter (original) (raw)
Last Updated : 07 Jun, 2019
Tkinter supports a variety of widgets to make GUI more and more attractive and functional. The PanedWindow widget is a geometry manager widget, which can contain one or more child widgets panes. The child widgets can be resized by the user, by moving separator lines sashes using the mouse.
Syntax: PanedWindow(master, **options)
Parameters:
master: parent widget or main Tk() object
options: which are passed in config method or directly in the constructor
PanedWindow can be used to implement common 2-panes or 3-panes but multiple panes can be used.
**Code #1:**PanedWindow with only two panes
from
tkinter
import
*
from
tkinter
import
ttk
root
=
Tk()
pw
=
PanedWindow(orient
=
'vertical'
)
top
=
ttk.Button(pw, text
=
"Click Me !\nI'm a Button"
)
top.pack(side
=
TOP)
pw.add(top)
bot
=
Checkbutton(pw, text
=
"Choose Me !"
)
bot.pack(side
=
TOP)
pw.add(bot)
pw.pack(fill
=
BOTH, expand
=
True
)
pw.configure(sashrelief
=
RAISED)
mainloop()
Output:
Code #2: PanedWindow with multiple panes
from
tkinter
import
*
from
tkinter
import
ttk
root
=
Tk()
pw
=
PanedWindow(orient
=
'vertical'
)
top
=
ttk.Button(pw, text
=
"Click Me !\nI'm a Button"
)
top.pack(side
=
TOP)
pw.add(top)
bot
=
Checkbutton(pw, text
=
"Choose Me !"
)
bot.pack(side
=
TOP)
pw.add(bot)
label
=
Label(pw, text
=
"I'm a Label"
)
label.pack(side
=
TOP)
pw.add(label)
string
=
StringVar()
entry
=
Entry(pw, textvariable
=
string, font
=
(
'arial'
,
15
,
'bold'
))
entry.pack()
entry.focus_force()
pw.add(entry)
pw.pack(fill
=
BOTH, expand
=
True
)
pw.configure(sashrelief
=
RAISED)
mainloop()
Output: