我想制作一个在 Tkinter 中启用拆分文本屏幕的窗口。我还希望能够用鼠标“拉伸”屏幕,例如,如果我希望其中一个屏幕暂时大于另一个,我只需用鼠标拖动它即可。
我想我可以在 PanedWindow 小部件中放置一个 Text 小部件,因为我认为 PanedWindow 小部件始终是可拉伸的,但我的代码并不能很好地完成这项工作。我能够获得分屏,但它们不可拉伸。到目前为止,这是我的(不必要的长而简单的)代码:
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()