在python 3.x中应用外部文件中的帧?
是否有任何方法将外部模块的帧应用于根窗口。 我有两个文件: 在里面 a.py 它有一行在python 3.x中应用外部文件中的帧?,python,python-3.x,class,oop,tkinter,Python,Python 3.x,Class,Oop,Tkinter,是否有任何方法将外部模块的帧应用于根窗口。 我有两个文件: 在里面 a.py 它有一行self.root=root(),我在一个导入b.py 和 在里面 b.py 我有一个类,并实例化了一个要显示在根窗口中的框架 self.frame=frame(根)。 没有错误,但框架小部件未显示在根窗口中。 我尝试在b.py文件中将root更改为self.root 例如: #file 'a' class Root: def __init__(self): self.root = ro
self.root=root()
,我在一个导入b.py
和
在里面
b.py
我有一个类,并实例化了一个要显示在根窗口中的框架
self.frame=frame(根)
。
没有错误,但框架小部件未显示在根窗口中。
我尝试在b.py文件中将root
更改为self.root
例如:
#file 'a'
class Root:
def __init__(self):
self.root = root()
root.title('Hello')
self.b = None
def boo(self):
import b
self.b = b.A()
Root.boo()
and
#file 'b'
class A:
def __init__(self):
self.frame = tk.LabelFrame(self.root)
self.frame.pack()
def __a_meth__(self):
Button(self.frame, text = 'YES')
Button.pack()
需要做哪些更改?通常,您会传入任何需要的内容:
#file 'a'
class Root:
def __init__(self):
self.root = root()
self.root.title('Hello')
self.b = None
def boo(self):
import b
self.b = b.A(self.root) # pass the root object in
self.b.__a_meth__() # don't forget to call this if you want to see anything
Root.boo()
肯定有错误,因为
A中未定义self.root
。\uuuu init\uuuu()
。谢谢,我找到了。错误是我将调用分配给了一个变量。我尝试了此操作,但该帧未在根窗口中打包。您需要显示一个,以便我们帮助您完成此操作。抱歉,但谢谢,我找到了答案。错误在于我没有传递对象并将其分配给变量。
#file 'b'
class A:
def __init__(self, root):
self.root = root
self.frame = tk.LabelFrame(self.root)
self.frame.pack()
def __a_meth__(self):
Button(self.frame, text = 'YES')
Button.pack()