-2

I keep getting the following error on a piece of python code:

Traceback (most recent call last):     
File"..."...in <module>   
app = App(root)  
TypeError: object.__new__() takes no parameters  

Here is the code it is referring to:

from tkinter import *
from ScaleAndOffsetConverter import *

class App():
    def __init_(self, master):

        self.c_var = DoubleVar()
        self.t_conv.ScaleAndOffsetConverter("F", "C", 1.8, 32)
        frame = Frame(master)
        frame.pack()
        L1 = Label(frame, textvariable = self.result_var)
        L2 = Label(frame, text = "Deg C")
        E = Entry(frame, textvariable=self.c_var)
        L3 = Label( frame, text = "Deg F")
        B = Button(frame, text = "convert", command = self.convert)
        L1.grid(row=1,column=1)
        L2.grid(row=1, column=0)
        E.grid(row=0, column=1)
        L3.grid(row=0,column=0)
        B.grid(row=2, columnspan=2)
        self.result_var = DoubleVar

     def convert(self):
           c = self.c_var.get()
           self.result_var.set(self.t_conv.convert(c))

root = Tk()
app = App(root)
root.wm_title("Temp Converter")
root.mainloop()

I know that similar questions have been posted to this one but i still don't fully understand how to fix this problem - does anybody know why it is appearing or how to fix it?

  • 2
    `self.t_conv.ScaleAndOffsetConverter` is also going to fail – Padraic Cunningham Dec 30 '15 at 01:21
  • 1
    Raspberry Pi and its Debian derivative are irrelevant to this question. I assume you added them because you're running the code there, but unless it's actually related to the OS, please don't add those tags. Additionally, I **hope** the indentation of `def convert(self)` is just a formatting mistake... – jpmc26 Dec 30 '15 at 01:25

1 Answers1

4

Your __init__() function is misspelled!

Replace

def __init_(self, master): with

def __init__(self, master):

Make sure there are double underbars before and after the word init. These functions are known as "dunder" methods and as you can see the number of underbars does matter!

Python looks for your implementation of __init__ and cannot find it, so it uses Object's __init__, which does nothing but check that no arguments have been passed to it according to this post. This check results in the TypeError you are seeing.

Community
  • 1
  • 1
Dylan Kirkby
  • 1,427
  • 11
  • 19