I want to make a window which enables split text screens in Tkinter. I also want to be able to "stretch" the screens with the mouse, so for example if I want one of the screens to be temporarily bigger than the other, I just drag it with the mouse.
I thought I could put a Text widget inside a PanedWindow widget since I thought the PanedWindow widget always is stretchable, but my code doesn't quite do the job. I'm able to get split screens, but they aren't stretchable. Here Is my (Unnecessary long but simple) code so far:
from Tkinter import *
root = Tk()
# Seems strange to column- and rowconfigure the root but if I don't -
# the text widgets won't resize at all
for i in range(4):
root.columnconfigure(0, weight=1)
for i in range(1,3):
root.rowconfigure(1, weight=1)
# make a master PanedWindow
m1 = PanedWindow(root)
m1.grid(column=0, row=0, rowspan=4, columnspan=4, sticky=E+N+W+S)
for i in range(4):
m1.columnconfigure(i, weight=1) # Enable vertical resizing
for i in range(1,3):
m1.rowconfigure(i, weight=1) #Enable horizontal resizing
# make a PanedWindow inside m1, positioned to the left
m2=PanedWindow(m1)
m2.grid(column=0, row=1, columnspan=2, rowspan=2, sticky=E+N+W+S)
for i in range(2):
m2.columnconfigure(i, weight=1) # Enable vertical resizing
for i in range(1,3):
m2.rowconfigure(i, weight=1) #Enable horizontal resizing
# make another PanedWindow inside m1, positioned to the right
m3=PanedWindow(m1)
m3.grid(column=2, row=1, columnspan=2, rowspan=2, sticky=E+N+W+S)
for i in range(2, 4):
m3.columnconfigure(i, weight=1) # Enable vertical resizing
for i in range(1,3):
m3.rowconfigure(i, weight=1) #Enable horizontal resizing
# Add a text widget in m2
text1 = Text(m2, height=15, width =15)
m2.add(text1)
# Add another textwidget in m3
text2=Text(m3, height=15, width=15)
m3.add(text2)
root.mainloop()
The main problem with your code is that you're not using
PanedWidnow
correctly. For example, you can'tpack
orgrid
onePanedWindow
inside another. To place one widget inside aPanedWindow
you must use the paned window.add()
method. So, to put m2 inside m1 you must dom1.add(m2)
. Treat aPanedWindow
like aFrame
, and.add()
is the equivalent to.pack()
or.grid()
.Also, it seems like you're thinking an
PanedWindow
is a pane, which it is not. If you want three panes for three side-by-side windows, you only need to create a single instance ofPanedWindow
, and then call.add(...)
three times, once for each child window. While you can put paned windows inside paned windows, it's rarely the right thing to do unless one is horizontal and the other is vertical. For most circumstances, a single instance ofPanedWindow
is all you need.