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

Recommended Answers

All 11 Replies

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.

You have the function but not call the function()

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.

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.

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.

For those who found this via a Google search, the answer doesn't have to be "Change to python 3". When I've had this problem, all I've had to do is append "object" class to the list of parent classes, so:

class Application(Frame):

becomes

class Application(Frame,object):

@Rufus_1 It is true that the answer doesn't have to be "change to python 3", however this is strongly recommended as python 2 support will end in 2020. Let me recall that classobj, or Old Style Classes are a typical python 1 relic which death was already planned when python 2.1 was released more than 16 years ago. I really liked python 1 myself, but if you want your code to survive many years, don't use prehistoric software :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.