我希望以下嵌套的PanedWindows 正确调整大小。
垂直PanedWindow应将窗口分成两半,水平应将上窗格水平分成两半。在每个窗格中,树视图是网格。那些Treeview具有不同数量的列,并且附加了滚动条。
感谢您的帮助!
# -*- coding: utf-8 -*-
import Tkinter as tk
import ttk
class Test(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.createUI()
self.mkLayout()
self.configResize()
self.mainloop()
def createUI(self):
self.paneV = ttk.PanedWindow(master=self, orient=tk.VERTICAL)
self.paneH = ttk.PanedWindow(master=self.paneV, orient=tk.HORIZONTAL)
self.frmA = ttk.Frame(master=self.paneH)
self.frmB = ttk.Frame(master=self.paneH)
self.frmC = ttk.Frame(master=self.paneV)
self.trvA = ttk.Treeview(master=self.frmA,
columns=('1', '2', '3', '4', '5', '6', '7',
'8', '9', '10'))
self.trvB = ttk.Treeview(master=self.frmB, columns=('1', '2', '3'))
self.trvC = ttk.Treeview(master=self.frmC,
columns=('1', '2', '3', '4', '5', '6'))
self.scrA = ttk.Scrollbar(master=self.frmA, orient=tk.HORIZONTAL,
command=self.trvA.xview)
self.scrB = ttk.Scrollbar(master=self.frmB, orient=tk.HORIZONTAL,
command=self.trvB.xview)
self.scrC = ttk.Scrollbar(master=self.frmC, orient=tk.HORIZONTAL,
command=self.trvC.xview)
def mkLayout(self):
self.trvA.grid(row=0, column=0, sticky=tk.NSEW)
self.trvB.grid(row=0, column=0, sticky=tk.NSEW)
self.trvC.grid(row=0, column=0, sticky=tk.NSEW)
self.scrA.grid(row=1, column=0, sticky=tk.EW)
self.scrB.grid(row=1, column=0, sticky=tk.EW)
self.scrC.grid(row=1, column=0, sticky=tk.EW)
self.paneV.grid(row=0, column=0, sticky=tk.NSEW)
self.paneH.add(self.frmA, weight=1)
self.paneH.add(self.frmB, weight=1)
self.paneV.add(self.paneH, weight=1)
self.paneV.add(self.frmC, weight=1)
def configResize(self):
self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
Test()
答案 0 :(得分:0)
好的,我解决了这个问题:
# -*- coding: utf-8 -*-
import Tkinter as tk
import ttk
class Test(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.geometry('800x600')
self.createUI()
self.mkLayout()
self.configResize()
self.mainloop()
def createUI(self):
self.paneV = ttk.PanedWindow(master=self, orient=tk.VERTICAL)
self.paneH = ttk.PanedWindow(master=self.paneV, orient=tk.HORIZONTAL)
self.frmA = ttk.Frame(master=self.paneH)
self.frmB = ttk.Frame(master=self.paneH)
self.frmC = ttk.Frame(master=self.paneV)
self.trvA = ttk.Treeview(master=self.frmA,
columns=('1', '2', '3', '4', '5', '6', '7',
'8', '9', '10'))
self.trvB = ttk.Treeview(master=self.frmB, columns=('1', '2', '3'))
self.trvC = ttk.Treeview(master=self.frmC,
columns=('1', '2', '3', '4', '5', '6'))
self.scrA = ttk.Scrollbar(master=self.frmA, orient=tk.HORIZONTAL,
command=self.trvA.xview)
self.scrB = ttk.Scrollbar(master=self.frmB, orient=tk.HORIZONTAL,
command=self.trvB.xview)
self.scrC = ttk.Scrollbar(master=self.frmC, orient=tk.HORIZONTAL,
command=self.trvC.xview)
self.trvA['xscroll'] = self.scrA.set
self.trvB['xscroll'] = self.scrB.set
self.trvC['xscroll'] = self.scrC.set
def mkLayout(self):
self.paneV.grid(row=0, column=0, sticky=tk.NSEW)
self.paneH.add(self.frmA, weight=1)
self.paneH.add(self.frmB, weight=1)
self.paneV.add(self.paneH, weight=1)
self.paneV.add(self.frmC, weight=1)
self.trvA.grid(row=0, column=0, sticky=tk.NSEW)
self.trvB.grid(row=0, column=0, sticky=tk.NSEW)
self.trvC.grid(row=0, column=0, sticky=tk.NSEW)
self.scrA.grid(row=1, column=0, sticky=tk.EW)
self.scrB.grid(row=1, column=0, sticky=tk.EW)
self.scrC.grid(row=1, column=0, sticky=tk.EW)
def configResize(self):
self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
self.frmA.grid_propagate(0)
self.frmB.grid_propagate(0)
self.frmC.grid_propagate(0)
self.frmA.columnconfigure(0, weight=1)
self.frmB.columnconfigure(0, weight=1)
self.frmC.columnconfigure(0, weight=1)
self.frmA.rowconfigure(0, weight=1)
self.frmB.rowconfigure(0, weight=1)
self.frmC.rowconfigure(0, weight=1)
Test()