我试图理解为什么未定义Home。我正在尝试创建一个简单的GUI应用程序,该应用程序会切换到Tkinter主框架中的下一个框架。每个按钮应移至下一页(课程)。我从一个基金会开始,所以我可以通过每种方式进行复制。这是我的错误:
builtins.AttributeError:类型对象“ Home”没有属性“ tk”
from tkinter import *
class mainframe(Frame):
def raise_frame(rootFrame):
rootFrame.tkraise
Home = Frame(root)
pageOne = Frame(root)
pageTwo = Frame(root)
for rootFrame in (Home, pageOne, pageTwo):
rootFrame.grid(row=0, column=0)
class Home(Frame):
def __init__(self, root):
Frame.__init__(self, root)
self.root = root
self.startIntro()
def startIntro(self):
self.introLabel = Label(self.root, text=" Welcome!", anchor=CENTER, background="white").pack()
self.introButton = Button(self.root, text='Go to Page 1', command= lambda:raise_frame(pageOne)).pack()
class pageOne(Frame):
def firstFrame(self):
self.firstLabel = Label(self.root, text='Page 1').pack()
self.firstButton = Button(self.root, text='Go to Page 2', command= lambda:raise_frame(pageTwo)).pack()
class pageTwo(Frame):
def secondFrame(self):
self.secondLabel = Label(self.root, text='Page 2').pack()
self.secondButton = Button(self.root, text='Return to Home', command= lambda:raise_frame(Home)).pack()
def main():
root=Tk()
root.geometry('600x600')
mainframe(Home)
root.mainloop()
if __name__ == '__main__':
main()