-1

I've come across this great tutorial - https://www.youtube.com/watch?v=jBUpjijYtCk&index=4&list=PLQVvvaa0QuDclKx-QpC9wntnURXVJqLyk

its part 3, its essentially just about being able to swap out frames with the press of a button. I've pretty much followed all the steps and everything works up until about 7.06

here is the code -

import Tkinter as tk

class MainApp(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,PageOne):

            frame = F(container,self)

            self.frames[F] = frame

            frame.grid(row = 0, column = 0, sticky = "w")

        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)

        lbl = tk.Label(self, text = "Start Page", font =("Helvetica",12,"bold"))
        lbl.pack()

        btn = tk.Button(self,text = "Button to next frame", font = ("Helvetica",12,"bold")
                    ,command =lambda: controller.show_frame(PageOne))
    btn.pack()

class PageOne(tk.Frame):
    def __int__(self,parent,controller):
        tk.Frame.__init__(self,parent)

        lbl = tk.Label(self, text = "page 1", font =("Helvetica",12,"bold"))
        lbl.pack()

        btn1 = tk.Button(self,text = "Button to pageOne", font = ("Helvetica",12,"bold")
                    ,command =lambda: controller.show_frame(StartPage))
        btn1.pack()


app = MainApp()
app.mainloop()

an error is thrown when I implement the loop -

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 2090, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: unknown option "-use"

I've scrutinised the code pretty carefully and can't see any differences so I'm not entirely sure what it means or why its comes up? or why the same thing doesn't happen in the video, any ideas?

Treeno1
  • 139
  • 1
  • 2
  • 18

1 Answers1

0

You've misspelled __init__ to be __int__ in PageOne, which means that the default __init__ is being run. The default __init__ method's second parameter is use rather than controller, which is why you get that particular error.

By the way, the code in that tutorial originated in a stackoverflow answer and then copied by the creator of that tutorial. You might find the original answer and some related answers useful:

https://stackoverflow.com/a/7557028/7432

Community
  • 1
  • 1
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685