Python 我想在特金特开一扇新窗户

Python 我想在特金特开一扇新窗户,python,tkinter,Python,Tkinter,我是python Tkinter的新手我想在点击开始按钮后出现一个新窗口我创建了一个新窗口的函数我真正的问题是我创建了一个带有三个self参数的类,家长和控制器我试着让函数新窗口有两个参数self和controller,但我不能,这是我做的最后一个实验,谢谢你的建议 class spariot(tk.Tk): def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) container

我是python Tkinter的新手我想在点击开始按钮后出现一个新窗口我创建了一个新窗口的函数我真正的问题是我创建了一个带有三个self参数的类,家长和控制器我试着让函数新窗口有两个参数self和controller,但我不能,这是我做的最后一个实验,谢谢你的建议

class spariot(tk.Tk):

def __init__(self, *args, **kwargs):

    tk.Tk.__init__(self, *args, **kwargs)
    container = tk.Frame(self)


    container.pack(side="top", fill="both", expand = True)

    container.grid_rowconfigure(0, weight=1)
    container.grid_columnconfigure(0, weight=1)


    self.frames = {}




    for F in(StartPage,History_page):
        frame=F(container,self)
        self.frames[F]=frame
        frame.grid(row=0, column=0, sticky="nsew")



    self.show_frame(StartPage)


def show_frame(self, cont):

    frame = self.frames[cont]
    frame.tkraise()
类StartPagetk.Frame:

def __init__(self, parent, controller):
    tk.Frame.__init__(self,parent)
    label = tk.Label(self, text="Start Page", font=LARGE_FONT)
    label.pack(pady=10,padx=10)
    button1=tk.Button(self,text="start",command =self.new_window)
    button1.pack()

    button2=tk.Button(self,text="history",command=lambda:controller.show_frame(History_page))
    button2.pack()
def new_window(self):
    self.newWindow = tk.Toplevel(self.master)
    self.app = StartingPage(self.newWindow)    

从小事做起,从小事做起。 下面的示例将从根窗口生成一个新窗口,以进行研究:

import tkinter as tk

def spawn():
    top = tk.Toplevel()
    tk.Label(top, text='this is a new bright\nand shiny\nnew window').pack()

root = tk.Tk()
btn = tk.Button(root, text='spawn new window', command=spawn)
btn.pack()

root.mainloop()

我创建了一个包含三个参数的类:您引用的是哪个类?什么是StartingPage,您没有显示这个类?谢谢您,先生,我已经解决了这个问题,将新窗口转换为命令可以调用的独立函数