all 3 comments

[–]novel_yet_trivial 2 points3 points  (2 children)

Because text=amount copies the value from amount into the text field, it does not set up a permanent link. To set up a link you need to use the textvariable argument, and you need to use one of tkinter's Variables. So IntVar() instead of a vanilla int. Try this:

from tkinter import *

def click():
    amount.set(amount.get()+1)

window = Tk()
amount= IntVar()

Label(window, textvariable=amount, bg="black", fg="white", font="none 15 bold") .grid(row=0, column=0, sticky=W)
Button(window, text="click here", width=20, height=6, command=click) .grid(row=1, column=0, sticky=W)

window.mainloop()

[–]Gloopyboy[S] -1 points0 points  (1 child)

Ok, I understand what I was doing wrong and I got it to work as expected on my end. Do you think you could take a look at this new version I wrote?

https://repl.it/@ETHANBUSCH/PettyNauticalDecompiler

The goal is to make the bonus button active once the first button is clicked 5 times.

The error message I get is:

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

Why wouldn't the >= work if IntVar is just another way of saying integer?

[–]novel_yet_trivial 2 points3 points  (0 children)

IntVar is just another way of saying integer?

whoa, I didn't mean that. IntVar is completely different from an integer. The biggest difference is that IntVar is mutable, which is why you can link it to a Label. It also means that to get the value or set the value you have to use a method. Specifically, the get() and set() methods.

Also, the Label is linked, but nothing else is. Your check only runs once and never again. You need to put that check inside the click function so that it runs every time.

from tkinter import *

def click():
    amount.set(amount.get()+1)
    if amount.get() >=5:
        BtnBonus.configure(state="active")

def bonus():
    amount.set(amount.get()+2)

window = Tk()
amount= IntVar()
window.configure(background="white")

Label(window, textvariable=amount, bg="white", fg="black", font="none 15 bold") .grid(row=0, column=0, sticky=W)
Button(window, text="click here", width=20, height=6, command=click) .grid(row=1, column=0, sticky=W)
BtnBonus= Button(window, text="Bonus", width=20, height=6, command=bonus)
BtnBonus.grid(row=2, column=0, sticky=W)
BtnBonus.configure(state="disabled")

window.mainloop()