This question already has an answer here:
- Add tkinter's intvar to an integer 2 answers
I'm trying to make a clicker game on python but I keep getting the error "TypeError: unorderable types: IntVar() > int()"
I have looked at other posts and still don't understand the .get
thing. here is my code so far:
import tkinter
from tkinter import *
import sys
root = tkinter.Tk()
root.geometry("160x100")
root.title("Cliker game")
global counter
counter = tkinter.IntVar()
global multi
multi = 1
def onClick(event=None):
counter.set(counter.get() + 1*multi)
tkinter.Label(root, textvariable=counter).pack()
tkinter.Button(root, text="I am Cookie! Click meeeeee", command=onClick,
fg="dark green", bg = "white").pack()
clickable = 0
def button1():
global multi
global counter
if counter > 79: # this is the line where the error happens
counter = counter - 80
multi = multi + 1
print ("you now have a multiplier of", multi)
else:
print ("not enough moneys!")
b = Button(text="+1* per click, 80 cookies", command=button1)
b.pack()
root.mainloop()
you have to compare identical types (or compatible types). In that case, it seems that the
IntVar
object cannot be directly compared toint
. But it has aget
method that returns an integer.I'm not a
tk
specialist but this reproduces the issue and provides a fix:in your case, change:
by
As comments suggested, you have those issues at other places. So use
.get
and.set
where integers &IntVar
objects are mixed.