__init __()缺少1个必需的位置参数:'controller'

时间:2017-01-15 16:07:26

标签: python tkinter controller project

收到以下错误:

TypeError:  __init__() missing 1 required positional argument: 'controller'.

我似乎无法让这个工作。如果您需要更多信息,请在下面留言。

from tkinter import *
import tkinter as tk


class SampleApp(tk.Tk):
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)

        # the container is where we'll stack a bunch of frames
        # on top of each other, then the one we want visible
        # will be raised above the others
        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 (App, pag2):
            page_name = F.__name__
            frame = F(parent=container, controller=self)
           self.frames[page_name] = frame

            # put all of the pages in the same location;
            # the one on the top of the stacking order
            # will be the one that is visible.
            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame("StartPage")

    def show_frame(self, page_name):
        '''Show a frame for the given page name'''
        frame = self.frames[page_name]
        frame.tkraise()


class App(tk.Frame):
    def __init__(self,master,controller):
        master.geometry("790x596")


        photo = PhotoImage(file="Naamloos.png")
        self.w = w = Label (master, image=photo)
        w.photo = photo
        w.pack()

        self.controller = controller
        self.hello_b = Button(master,text="Actuele vertrekken",command=lambda: controller.show_frame("pag2"), height=3,
                          width=18,fg= "white",bg = "#00339C")
        self.hello_b.place(x=178, y=387)

class pag2(tk.Frame):
    def __init__(self, master, controller):
        master.geometry("790x596")

        self.controller = controller
        photo = PhotoImage(file="Naamloos2.png")
        self.w = w = Label (master, image=photo)
        w.photo = photo
        w.pack()

        self.hello_b = Button(master,text="Actuele vertrekken",command=lambda: controller.show_frame("App"), height=3,
                          width=18,fg= "white",bg = "#00339C")
        self.hello_b.place(x=178, y=387)

    root = Tk()
    root.title("Kaartautomaat")
    app = App(root)
    root.mainloop()

1 个答案:

答案 0 :(得分:1)

您声明App.__init__有两个参数(mastercontroller),但您只能在调用它时提供一个(app = App(root))。您需要为该调用提供适当的第二个参数。

c = ???
app = App(root, c)
相关问题