不确定它是否是您要查找的内容,但您可以在主 Tk 中创建两个框架。
import tkinter as tk
class SubWindow(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
x = tk.Text(self)
x.pack()
class MainWindow(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self)
self.win1 = SubWindow(self)
self.win1.pack(side="left")
self.win2 = SubWindow(self)
self.win2.pack(side="right")
if __name__ == "__main__":
main = MainWindow()
main.mainloop()
编辑:
这是在窗口执行时使框架调整大小的代码:
import tkinter as tk
class SubWindow(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
x = tk.Text(self)
x.pack(expand=1, fill='both')
class MainWindow(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self)
self.win1 = SubWindow(self)
self.win1.pack(side="left", expand=1, fill=tk.BOTH)
self.win2 = SubWindow(self)
self.win2.pack(side="right", expand=1, fill=tk.BOTH)
if __name__ == "__main__":
main = MainWindow()
main.mainloop()