I am creating a program for scorekeeping basketball. I have a few different files with classes and what not. My main problem is trying to update the points of each players.
For example:
I have a button set up on the screen;
pointsButton = Button(root, text='1PT', command=addPoint)
pointsButton.grid(row=0, column=1)
And a label next to that, that calls the points of a specific player (supposedly).
plabel = Label(root, text=(str(p.points)), relief='groove', bg='#41B6E6', fg = '#DB3EB1', padx=numX, pady=numY)
plabel.grid(row=rowNumber, column=4)
Here's the code from my player class that is probably needed to understand my problem.
class BasketballPlayer:
#Constructor
def __init__(self , preName, lastName, jerseyNumber):
self.preName = preName
self.lastName = lastName
self.jerseyNumber = jerseyNumber
self.points = 0
self.assists = 0
self.rebounds = 0
self.steals = 0
self.blocks = 0
self.fouls = 0
self.threePointers = 0
self.careerHighPoints = 0
self.careerHighAssists = 0
self.careerHighRebounds = 0
self.careerHighSteals = 0
self.careerHighBlocks = 0
self.careerHighThreePointers = 0
And a couple functions from the class:
def addPoints(self, p):
self.points += p
def incrementOnePoint(self):
self.points += 1
def getPoints(self):
return self.points
Here's a couple functions I've tried.
def addPoint():
p.incrementOnePoint()
plabel.config(text=p.points)
Or:
def addPoint():
p.addPoints(1)
plabel.config(text=p.points)
I really thought it would just automatically update because I'm adding a integer to a variable, but it's not updating at all.
Here is a minimal reproducible example as requested in the comments.
from tkinter import *
root = Tk()
class bballPlayer:
def __init__(self):
self.points = 0
def incrementOnePoint(self):
self.points += 1
def getPoints(self):
return self.points
def addOnePoint():
p.incrementOnePoint
global pointslabel
pointslabel.config(text=str(p.points))
p = bballPlayer()
pointslabel = Label(root, text=str(p.points))
pointslabel.grid(row=0, column=1)
btn = Button(root, text='Add Point', command=addOnePoint)
btn.grid(row=0, column=0)
root.mainloop()