Hello, I was testing a class in a GUI, and that error message showed up. Please help.

Code:

from Tkinter import *

class Application(Frame):
    def __init__(self, master):
        super(Application, self).__init__(master)
        self.grid
        self.create_widgets()
        
    def create_widgest(self):
        self.bttn1 = Button(self, text = "I do nothing!")
        self.bttn1.grid()
        self.bttn2 = Button(self, text = "Me too.")
        self.bttn2.grid()
        self.bttn3 = Button(self, text = "Same here..")
        self.bttn3.grid()
        
    
root = Tk()
root.title("Lazy buttons")
root.geometry("200x100")
app = Application(root)
root.mainloop

Why you are not calling the mainloop at last line? Shouldn't the parameter to parent init be self?

Ain't the mainloop already at last line? the 'parent' is the superclass right? I've changed it so that is says:

super(Application, self).__init__(self, master)

Still same problem.

Alright, changed it.

The code should be fine. but still an error comes.

class Application(Frame):
    def __init__(self, master):
        super(Application, self).__init__(self, master)
        self.grid
        self.create_widgets()
        
    def create_widgest(self):
        self.bttn1 = Button(self, text = "I do nothing!")
        self.bttn1.grid()
        self.bttn2 = Button(self, text = "Me too.")
        self.bttn2.grid()
        self.bttn3 = Button(self, text = "Same here..")
        self.bttn3.grid()
        
    
root = Tk()
root.title("Lazy buttons")
root.geometry("200x100")
app = Application(root)
root.mainloop()

error:
app = Application(root)
super(Application, self).__init__(self, master)
TypeError: must be type, not classobj

I can not test now but I would call self as only parameter,

Frame.__init__(self)

works and also

Frame.__init__(self, master)

, I think you have problem with the super syntax. Personally I use directly the inherited class name. You have other errors in your program, but let's you find them yourself.

Edited 5 Years Ago by pyTony: n/a

The error 'TypeError: must be type, not classobj ' usually appears in python 2 when an old style class instance is used in a function where a new style class instance is expected. Aren't you using an old version of python where Tkinter classes are old style classes ? If this is the case, you could try and add 'object' to the superclasses of your Application class.

Edited 5 Years Ago by Gribouillis: n/a

Uh oh he's using the same book I was using, lol.

This worked fine for me:

from tkinter import *

class Application(Frame):
    def __init__(self, master):
        super(Application, self).__init__(master)
        self.grid()
        self.create_widgets()
        
    def create_widgets(self):
        self.bttn1 = Button(self, text ="I do nothing!")
        self.bttn1.grid()
        self.bttn2 = Button(self, text ="Me too.")
        self.bttn2.grid()
        self.bttn3 = Button(self, text ="Same here..")
        self.bttn3.grid()
        
    
root = Tk()
root.title("Lazy buttons")
root.geometry("200x100")
app = Application(root)
root.mainloop()

your issue was primarily sloppiness, pay attention to your code, you misspelled alot and forgot to call a new instance of events like grid which should've been grid()<--() is important.

Also make sure you're using python 3

Hey, thanks for the help! I've now got Python 3.2, and it seems to work better, there are just some other errors now, I'll try to figure it out myself.

Pyguy62, if you finished the book, what would be your rating of it? (0/10)

abders, I would rate it an 7-8/10, it's great for learning but I can teach some bad habits and be unclear at times, but supplemented with Daniweb it can be acceptable.

This question has already been answered. Start a new discussion instead.