Question

So I have lifted this code straight from the book: Programming the Raspberry Pi; Getting started with Python by Simon Monk:

from tkinter import *

class App:

    def _init_(self,master):
        frame=Frame(master)
        frame.pack
        Label(frame, text='deg C').grid(row=0, column=0)
        button = Button(frame, text='Convert', command=self.convert)
        button.grid(row=1)

    def convert(self):
        print('Not implemented ')

root = Tk()
root.wm_title('Temp Conv')
app = App(root)
root.mainloop()

However, when I run it it returns the error that

line 18, in <module>
    app = App(root)
TypeError: object() takes no parameters

Any help would be appreciated!

Was it helpful?

Solution

you need 2 _ marks before and after init

Thats the format recognized by python as the init function. since you only put 1 before and after its not recognizing the "init" correctly and thinks its a user created function named "init". Which means the program thinks there isn't a "init"specified therefore no parameters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top