I am creating a simulator in pygame for school. I have created 3 buttons, which change colur when you hover. However, I want one of the buttons to have smaller text in. Currently, to set the text I have it within a class, but not as a method. I have made the button smaller when calling it as an instance, but I am not sure how to make the text smaller for this button, without changing the text in the others.
this is my code for my button class
class button():
def __init__(self, color, x , y , width , height , text=''):
self.color = color
self.x = x
self.y = y
self.width = width
self.height = height
self.text = text
def draw(self,win,outline= None):
if outline:
pygame.draw.rect(win, outline, (self.x-2 , self.y-2, self.width+4, self.height+4),0)
pygame.draw.rect(win, self.color, (self.x , self.y , self.width, self.height),0)
if self.text != '':
font = pygame.font.SysFont( "Times New Roman,Arial",40, bold = True)
text = font.render(self.text, 1 , (0,0,0))
win.blit(text, (self.x +(self.width/2 - text.get_width()/2), self.y + (self.height/2 - text.get_height()/2)))
def isOver(self,pos):
if pos[0] > self.x and pos [0] < self.x + self.width:
if pos [1] > self.y and pos[1] < self.y + self.height:
return True
return False
def redrawWindow():
userButton.draw(win,(0,0,0))
passButton.draw(win,(0,0,0))
loginButton.draw(win,(0,0,0))
this is the code for creating the instances:
userButton = button((TURQUOISE), 300,225,400,100, 'Username' )
passButton = button((TURQUOISE), 300,350,400,100, 'Password' )
loginButton = button((TURQUOISE), 465,470,100,25, 'Login' )