samedi 19 juin 2021

Python, If statement error with variables says not defined

I am having a problem when I am trying to use the if statement in python. I cannot see if a variable is true or false because it says the variable is not defined but I defined it in a method.

I am using kivy and kivyMD as well, just in case people were wondering why some of the code was there.

from kivymd.app import MDApp
from kivymd.uix.screen import Screen
from kivymd.uix.button import MDRectangleFlatButton, MDRoundFlatButton
from kivymd.uix.textfield import MDTextField
from kivy.lang import Builder
from kivymd.uix.menu import MDDropdownMenu

class DemoApp(MDApp):
    def show_data(self):
        inputFahrenheit = self.root.ids.fahrenheit.text
        if fahrenheit1 is True:
            Celsius_Half = float(inputFahrenheit) - 32 
            Celsius_Before_Round = Celsius_Half * 5/9

            Celsius = round(Celsius_Before_Round , 1)

    def convert1F(self):
        fahrenheit1 = True
        celsius1 = False

    def convert1C(self):
        fahrenheit1 = False
        celsius1 = True

    def convert2F(self):
        fahrenheit2 = True
        celsius2 = False

    def convert2C(self):
        fahrenheit2 = False
        celsius2 = True

    def on_start(self):
        self.theme_cls.primary_palette = "Green"
        self.theme_cls.primary_hue = "A700"
        self.theme_cls.theme_style = "Light"

    def build(self):
        kv = Builder.load_file("test.kv") 
        screen = Screen()
        return kv
            
    
DemoApp().run()

The if statement is the problem there is a copy of the problem: "fahrenheit1" is not defined

Aucun commentaire:

Enregistrer un commentaire