Home > Software engineering >  not supported between instances of 'Button' and 'int' tkinter
not supported between instances of 'Button' and 'int' tkinter

Time:11-16

im making a guess number game but i have a problem:In general, I would like to say how the process of the program is like this: the user first enters the number and clicks the registration option,The second user should try to guess what the number is in a specific number, but my problem is that if I want to create a while loop, it is not possible and it gives an error.

>> not supported between instances of 'Button' and 'int' py

my codes:

from tkinter import *
win = False
sum_1 = 0
def sumbit():
    global asghar
    asghar = int(text.get())
    text.pack_forget()
    sum_1.pack_forget()
    return asghar
def gusses():
    global sum_1
    while sum_1 > 10:
        a = int(text_1.get())
        if a == asghar:
            win = True
            print("you win")
            break
        elif a > asghar:
            print("number is higher")
            sum_1 = 1
        elif a < asghar:
            Label(app,text="number is lower").pack()
            sum_1 =1
app = Tk()
sumbit
app.minsize(300,300)
text = Entry(app,font=20)
text.pack()
text_1 = Entry(app,font=20)
text_1.pack()
sum_1=Button(app,text="player 1 sumbit",font=20,command=sumbit)
sum_1.pack()
Button(app,text="gusses",font=20,command=gusses).pack()
app.mainloop()

CodePudding user response:

In the beginning, your code sets sum_1 to an integer (0). You later make a button and set the same variable to that button. The gusses() function expects sum_1 to be an integer, so the button should probably have a different name.

CodePudding user response:

sum_1 is an Button object. You are trying to compare it to an integer. This isn't possible. Not sure what you are trying to do here. If you are wanting the text of sum_1 then you need to do int(sum_1['text']).

Edit: As pointed out by @Thingamabobs button.text doesn't work, use button['text'] instead

  • Related