conecat
conecat

Reputation: 3

Tkinter label text is a funtion object instead of text

I've been googling around for over an hour at this point, but I can't figure this out. I want to display the result of the function as the label's text. The problem is that even though the return of the function is for example: 250.2, when I place the label into the tkinter window, it looks more like (numbers)< lambda >, which I think is a function object.

The label:

self.temperature = ttk.Label(
            self,
            text=lambda:self.displayInfo(0))

The function:

def displayInfo(self, index):
        self.infoList = WeatherInfo.jsonToString(self)
        
        return self.infoList[index]

Thanks in advance.

Upvotes: 0

Views: 47

Answers (1)

Tim Roberts
Tim Roberts

Reputation: 54698

You are passing a lambda where a string is expected. If you want the result of the function, then just call the function:

self.temperature = ttk.Label( self, text=self.displayInfo(0) )

Upvotes: 1

Related Questions