在我的 MVC 应用程序中,我想从 xml 文件加载数据,并在一个窗格窗口的两个不同视图中显示它。在左窗格中,我想在 tk.ttk.Treeview 中显示数据。在右窗格中,我想在 tk.tkk.Canvas 中显示数据。
主要应用:
from lscController import Controller
if __name__ == '__main__':
c = Controller()
c.run()
控制器:
try:
import Tkinter as Tk # python 2
except ModuleNotFoundError:
import tkinter as Tk # python 3
from lscView import LSCGUI
class Controller:
def __init__(self):
self.root = Tk.Tk()
self.model = LSCDocument('name')
self.view = LSCGUI(self.root, self.model)
def run(self):
self.root.title("MVC Charts")
self.root.deiconify()
self.root.mainloop(
文件lscTreeView.py:
class LSCTree():
def __init__(self, window,model):
super().__init__()
frame = tk.Frame(window)
frame.pack()
我想将视图添加到文件lscView.py中 PanedWindow 的左窗格:
class LSCGUI():
def __init__(self, window, model):
super().__init__()
self.window = window
self.window.title("Model")
self.model = model
''' Full Screen Or not '''
self.window.attributes('-fullscreen',False)
self.window.geometry('800x600')
''' ________Frame as paned windows (left / right)________ '''
pwstyle = tk.ttk.Style()
pwstyle.configure('TPanedwindow ', foreground='green')
self.frame = tk.ttk.PanedWindow(style='TPanedwindow',orient=tk.VERTICAL)
self.frame.pack(fill=tk.BOTH, expand=True)
self.treeview=TREE.LSCTree(self.frame,model)
self.frame.add(self.treeview)
并得到这个错误:
_tkinter.TclError: bad window path name "<lscTreeView.LSCTree object at 0x00000222D62B5910>"
VS Code 说错误在这里: self.frame.add(self.treeview)