Search code examples
pythonintegertuplestkinter-entry

Issue with turning tuple entry variables into an int for a math problem


currently I've been trying to have my tuple variables: tempLentry,windLentry,dewpointLentry, be converted into an integer so I can use them in the math sequence. However I keep getting this error whenever it happens: TypeError: int() argument must be a string, a bytes-like object or a real number, not 'Entry'. I was hoping someone could point in the right direction, Thank you!

The code is below

def calc ():    
    #Tuple being recieved from askUser
    tempLentry,windLentry,dewpointLentry = askUser()

    #Converts string input from entries to integers for the calculations to work.
    t = int(tempLentry)
    ws = int(windLentry)
    dp = int(dewpointLentry)

    #Checks to see if inputed data for temperature and windspeed is less than 50mph and 
    greater than 3 mph
    if (t < 50 and ws > 3):
        windchill = (35.74 + 0.6215 * t - (35.75 * math.pow(ws,0.16)) + (0.4275 * t * math.pow(ws,0.16)))
    else:
        windchill = 0

Solution

  • You need to first convert the Entry to a string, and then cast it to an int.

    You can get the Entry as a string by using .get()

    t = int(tempLentry.get())
    ws = int(windLentry.get())
    dp = int(dewpointLentry.get())