Python MVC style GUI Temperature Converter Python MVC style GUI Temperature Converter tkinter tkinter

Python MVC style GUI Temperature Converter


You have two mistakes here:

1 - In your Counter.py file and in your Convert class methods, you are not return the right variables, instead of return celsius you should return self.celsius and same goes for self.fahrenheit

2 - In Controller.py file:

self.view.outputLabel["text"] = self.model.convertToFahrenheit(celsius) This will not update the label, instead you should do something like:

result = str(self.model.convertToFahrenheit(float(celsius))) #need to convert to stringself.view.outputLabel.config(text=result) #update the label with result

Same goes for buttonPressed2 method

EDIT-1:

Better change your equations in your Convert class to return correct float result:

self.celsius = float((fahrenheit - 32.0) * (0.56))

self.fahrenheit = float((celsius * 1.8) + 32.0)

EDIT-2:This is what your buttonPressed1 method of Convert Class should be:

def buttonPressed1(self):        celsius = self.view.entrySpace.get()        result = str(self.model.convertToFahrenheit(float(celsius)))        self.view.outputLabel.config(text=result)

And for buttonPressed2 as:

def buttonPressed2(self):        fahrenheit = self.view.entrySpace.get()        result = str(self.model.convertToCelsius(float(fahrenheit)))        self.view.outputLabel.config(text=result)