0

I'm working on looking up a cell value, and if that cell has nothing entered I want my code to do nothing, else I want to place a label on a Tkinter canvas, for some reason no matter what I do the label always ends up showing up, should the below code work?

        ##Grabbing the cell value from that indexed row and specific column, in this case pulling the value of indexed cell and column "Zixi Device"
        Searched_Service_Row_Location_B = (excel_data_df.iloc[Searched_Service_Row_Location]["Zixi Device"])
        Searched_Service_Row_Location_B_Value = (Searched_Service_Row_Location_B.values)

I am then taking the var Searched_Service_Row_Location_B_Value in an IF statment

    if Searched_Service_Row_Location_B_Value == None:
        pass
    else:
        Source1 = Label(Standard_window, text=Searched_Service_Row_Location_B_Value)
        Source1.place(x=60, y=100)

The Source1 label always shows up, even though the cell value stored in the var has nothing entered in the excel document.

Josh
  • 353
  • 3
  • 13
  • This should help: https://stackoverflow.com/questions/23086383/how-to-test-nonetype-in-python – Namandeep_Kaur Aug 21 '20 at 03:06
  • May have jumped the gun being happy, I tried most of the examples in that and still no luck, one thing is, I have one function calling another function, and I have the if statement in the function being called, I cannot imagine that is a problem? – Josh Aug 21 '20 at 03:27
  • it means `Searched_Service_Row_Location_B_Value` is not `None` – acushner Aug 21 '20 at 03:36
  • I think that's where I'm lost. The cell in my excel document has nothing entered and is a blank cell – Josh Aug 21 '20 at 03:50
  • I should say when I print the value it does print [nan] so perhaps it believes there is a value? – Josh Aug 21 '20 at 03:58
  • 1
    nan? Not a number? Then try giving `if Searched_Service_Row_Location_B_Value == '[nan]': pass` ? – Delrius Euphoria Aug 21 '20 at 09:35
  • I thought that would do it but sadly the same thing.. `if Searched_Service_Row_Location_B_Value == '[nan]': pass else: Source1 = Label(Standard_window, text=Searched_Service_Row_Location_B_Value) Source1.place(x=60, y=100)` Here is the value of Searched_Service_Row_Location_B_Value when I print it "[nan]" yet that still does not work. – Josh Aug 21 '20 at 14:58
  • @CoolCloud I never came back to say that was it, I did have to throw in (None, "[nan]") which I hope to understand at some point. I appreciate you pointing that out, as I would probably be banging my head on my desk still. Kudos – Josh Aug 25 '20 at 03:41
  • @josh That's weird but fine – Delrius Euphoria Aug 25 '20 at 06:19

1 Answers1

0

This seems to work the way I want it to

    if str(Searched_Service_Row_Location_B_Value) in (None, "[nan]"):
        pass
    else:
        Source1 = Label(Standard_window, text=Searched_Service_Row_Location_B_Value)
        Source1.place(x=60, y=100)
Josh
  • 353
  • 3
  • 13