Ben Briddon
Ben Briddon

Reputation: 33

Parameter 'event' value is not used

I'm developing a program in python 2.7 and have run into an issue on Pycharm. In the program, I want the user to be able to navigate through different screens by either clicking buttons, or by pressing the "enter" key. I tried implementing it into my program, and it works but Pycharm is giving the error

Parameter 'event' is not used

    import Tkinter as Tk


    class MemoryGameApp(Tk.Tk):
        def __init__(self, *args, **kwargs):
            Tk.Tk.__init__(self, *args, **kwargs)
            Tk.Tk.wm_title(self, "2 screens")
            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, PageTwo):
                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()

    class StartPage(Tk.Frame):
        def __init__(self, parent, controller):
                Tk.Frame.__init__(self, parent)
                label = Tk.Label(self, text="Page 1")
                label.pack()
                global button
                button = Tk.Button(self, text="Next", width=5, command=lambda: controller.show_frame(PageTwo))
                button.pack(pady=100, padx=100)
                button.focus_set()

                def press_enter(event):
                    controller.show_frame(PageTwo)
                    button2.focus_set()

                button.bind("<Return>", press_enter)

    class PageTwo(Tk.Frame):
            def __init__(self, parent, controller):
                Tk.Frame.__init__(self, parent)
                label_title2 = Tk.Label(self, text="Page 2")
                label_title2.pack()
                global button2
                button2 = Tk.Button(self, text="Back", width=5, command=lambda: controller.show_frame(StartPage))
                button2.pack(pady=100, padx=100)

                def press_enter(event):
                    controller.show_frame(StartPage)
                    button.focus_set()

                button2.bind("<Return>", press_enter)

    app = MemoryGameApp()
    app.mainloop()

It has given the error in def press_enter(event):

It claims that event is not used, but if I remove it from the program, the program does not function correctly

I know that it works when it is implemented, I'm just interested in seeing if there's anyway that I can remove this issue.

Thanks

Upvotes: 2

Views: 5833

Answers (2)

PChemGuy
PChemGuy

Reputation: 1699

It is sufficient to change event to _event.

Upvotes: 3

Gulius Jaesar
Gulius Jaesar

Reputation: 101

To remove this warning, you could replace the argument 'event' by '_', or just do something with the object, like printing it to console.

Even though the argument of the function seems useless, it cannot be removed: It belongs to the signature of a valid event function.

Upvotes: 10

Related Questions