die folgende Fehlermeldung bekommen:__init __() 1 erforderlich Positions Argument fehlt: 'Controller'
TypeError: __init__() missing 1 required positional argument: 'controller'.
Ich kann irgendwie nicht scheinen, diese Arbeit zu bekommen. Wenn Sie weitere Informationen benötigen, hinterlassen Sie bitte einen Kommentar.
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()
Fixieren Sie Ihre Einrückung. – chepner
Woher bekommst du den Fehler? –
Also, der Fehler sagt Ihnen, dass Sie ein Argument (mit dem Namen 'Controller') fehlen, und wenn Sie schauen, wo Sie die Klasse instanziieren (' app = App (root) ') fehlt Ihnen tatsächlich ein Argument. Was ist damit nicht klar? –