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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With