I'm trying to get the label called display to change the text whenever I press the button. My goal is, that it displays the value of gamer.trueCount, but I tried many approaches and I didn't manage to solve it. Could anyone help me?
from tkinter import *
#Constants
BUTTONWIDTH = 20
BUTTONHEIGHT = 10
LABELSIZE = 20
#Settings
DEFAULT_DECK_COUNT = 6
#DEFAULTFONT = ()
class util:
def __init__(self):
self.remainingDecks = 6
self.runningCount = 0
self.trueCount = 0
def update(self):
if(self.runningCount or self.remainingDecks) == 0: return
else: self.trueCount = (self.runningCount/self.remainingDecks)
print(self.trueCount)
def add(self) -> None:
self.runningCount += 1
self.update()
return
def subtract(self) -> None:
self.runningCount -= 1
self.update()
return
class Window(Frame):
def __init__(self, master = None):
Frame.__init__(self, master)
self.master = master
self.pack(expand = 1, fill = BOTH)
display = Label(self, width=LABELSIZE, height=int(LABELSIZE/2), text=str(gamer.trueCount)).pack()
addButton = Button(self, width=BUTTONWIDTH, height=BUTTONHEIGHT, text = "+", command= lambda : gamer.add()).pack()
subtractButton = Button(self, width=BUTTONWIDTH, height=BUTTONHEIGHT, text="-", command= lambda : gamer.subtract()).pack()
root = Tk()
gamer = util()
app = Window(root)
root.mainloop()