我需要tkinter框架处理和调用对象的帮助。这是我的例子:
from tkinter import *
class Main(Tk):
def __init__(self):
Tk.__init__(self)
self.frame_one = Frame(self)
self.frame_two = Frame(self)
self.frame_one.pack()
self.frame_two.pack()
self.someclassobj = SomeClass(self.frame_one)
self.someclassobj.pack()
class SomeClass(Frame):
def __init__(self, master):
Frame.__init__(self)
self.frame = Frame(master)
self.frame.pack()
self.btn = Button(self.frame, text='click', command=self.btn_func)
self.btn.pack()
def btn_func(self):
Main.someclassobjtwo = SomeClassTwo(Main.frame_two)
Main.someclassobjtwo.pack()
class SomeClassTwo(Frame):
def __init__(self, master):
Frame.__init__(self)
self.frame = Frame(master)
self.msg = Label(self.frame, text='some msg')
self.msg.pack()
app = Main()
app.mainloop()
我需要在SomeClassTwo
调用Main.frame_two
的对象,但我得到AttributeError: type object 'Main' has no attribute 'frame_two'
我真的不知道为什么会这样。