Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: super() argument 1 must be type, not classobj [duplicate]

from Tkinter import *

class Application(Frame):
    def __init__(self, master):
        super(Application, self).__init__(master)
        self.grid()
        self.bttnClicks = 0
        self.createWidgets()

    def createWidgets(self):
        self.bttn = Button(self)
        self.bttn["text"] = "number of clicks"
        self.bttn["command"] = self.upadteClicks
        self.bttn.grid()


    def upadteClicks(self):
        self.bttnClicks += 1
        self.bttn["text"] = "number of clicks " + str(self.bttnClicks)

root = Tk()
root.title("button that do something")
root.geometry("400x200")
app = Application(root)
root.mainloop()`

That's the error:

super(Application, self).__init__(master)
TypeError: super() argument 1 must be type, not classobj

What am I doing wrong? The code worked fine in python 3.XX but in python 2.XX it doesn't.

like image 343
misza Avatar asked May 21 '26 18:05

misza


1 Answers

Frame is not a new-style class, but super requires new-style classes to work. In python-3.x where everything is a new-style class the super will work properly.

You need to hardcode the superclass and method in python 2:

Frame.__init__(self, master)

Like they do in the official documentation.

like image 125
MSeifert Avatar answered May 26 '26 20:05

MSeifert