Hello.
I have a Class in my python file. That Class contains some functions.
How can i set the command of a Tkinter butten so that call a function of that class?

I tried this but it didn't work:

class calculating(object):
    def __inint__(self):
        self.current = 0
    def addition(self, amount):
        self.current += amount
    def result(self):
        return self.current
        print (self.current)
    def show(self):
        lbl["text"] = result()


btn1 = Button(root, text = "add", command = calculating.addition)
btn1.pack()

btn2 = Button(root, text = "result", command = calculating.show)
btn2.pack()

lbl = Label(root)
lbl.pack

I see that your __init__ method is misspelled, but you're gonna want an instance to work with. You have a calculating class, but no object. Instantiate the class:

mycalc = calculating()

...then use the method (mycalc.addition). Also, its good practice in python for classes to start with a capital letter. So calculating should be called Calculating instead.

There are a lot of mistakes in that code!
Maybe you should study up on Python class and argument passing in Tkinter Button command.

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.