'>' not supported between instances of 'IntVar' and 'IntVar'

Viewed 514

I am a new programmer, so please go easy on me. I am trying to take the Entry from the user and transform it into an int and then run the while loop assuming that the user inputs a number. When I try to run this code on the while loop (line 13) I get this error code: Exception has occurred: TypeError '>' not supported between instances of 'IntVar' and 'IntVar'

My code:

import smtplib
from tkinter import *

window = Tk()
AMNT_REPEAT= Entry(window, width=35, bg="white")
AMNT_REPEAT.grid(row=6, column=2, sticky=W)

AMNT_REPEAT = IntVar()
x = 0

x = IntVar()

while AMNT_REPEAT > x :
    def click():
        global YOUR_EMAIL_ADDRESS , YOUR_PASSWORD , AMNT_REPEAT , 
TARGET_EMAIL , subject , msg
        YOUR_EMAIL_ADDRESS=YOUR_EMAIL_ADDRESS.get()
        YOUR_PASSWORD=YOUR_PASSWORD.get()
        TARGET_EMAIL=TARGET_EMAIL.get()
        subject=subject.get()
        msg=msg.get()
        AMNT_REPEAT=AMNT_REPEAT.get()

        send_email(subject, msg)

    AMNT_REPEAT = AMNT_REPEAT -1    
2 Answers

In this line:

while AMNT_REPEAT > x :

You compare two IntVar instances which raises a TypeError. My guess is that you want to compare their values, which would be done by:

while AMNT_REPEAT.get() > x.get():

P.S. In the code you do:

x = 0

x = IntVar()

The first declaration is superfluous as it will be overridden immediately by the second one.

IntVar() types don't support comparison so you have to convert them to int.

Change:

AMNT_REPEAT > x

To:

AMNT_REPEAT.get() > x.get()
Related