[英]apply frame from external file in python 3.x?
有什么方法可以将外部模块的框架应用到根 window。 我有 2 个文件:在a.py中包含self.root = root()
行,我在 class 中有一个 function ,它导入b.py和在b.py中我有一个 ZA2F2ED4F8EBC2CBB4C21A29DC4 实例化的框架以显示在 root1DZAB 中window self.frame = Frame(root)
。 没有错误,但框架小部件未显示在根 window 中。 我尝试在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()
#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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.