I'm trying to get the text boxes to populate in ascending order e.g. button 2 fills text box 1 if clicked first. Currently the bellow code has each button tied to a textbox but I am trying to fix this to be used on a larger scale app (with 12 buttons available).
this is for my major project in school so any help is appreciated (the full version runs and looks better)
This is the minimum code needed to run
import pygame, sys
click = bool
pygame.init()
clock = pygame.time.Clock()
screen = pygame.display.set_mode((1200, 800), 0, 32)
font3 = pygame.font.SysFont(None, 25)
Item1 = ''
Item2 = ''
Item1_rect = pygame.Rect(780, 33, 400, 547)
Item2_rect = pygame.Rect(780, 58, 400, 547)
Colour = pygame.Color(0,0,0)
found =False
keys = pygame.key.get_pressed()
click = pygame.MOUSEBUTTONDOWN
sc1_num = 0
sc1_price = 0
sc2_num = 0
sc2_price = 0
def Main_sales():
#this area of the code was reused from a previous file
#which is an example of the RAD approach.
#~~~~~~~~~~~~~~~~~Start Code applied from previous programs~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
global Item1, Item2, Item1_rect, Item2_rect, click, sc1_num, sc1_price, sc2_num, sc2_price
while True:
for event in pygame.event.get():
if event.type == QUIT:
print("Quit")
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
click = True
screen.fill((255, 255, 255))
text1_surface = font3.render(Item1, True, (0,0,0))
screen.blit(text1_surface, (Item1_rect.x+20 , Item1_rect.y +100))
text2_surface = font3.render(Item2, True, (0,0,0))
screen.blit(text2_surface, (Item2_rect.x+20 , Item2_rect.y +100))
mx, my = pygame.mouse.get_pos()
b_w = 180
b_h = 70
b3_x = 55
b3_y = 200
b4_x = 275
b4_y = 200
button_3 = pygame.Rect( b3_x, b3_y ,b_w, b_h)
button_4 = pygame.Rect( b4_x, b4_y ,b_w, b_h)
if Item1 == '':
Empty_row = 1
elif Item2 == '':
Empty_row = 2
print(Empty_row)
if button_3.collidepoint(mx, my):
if click:
sc1_num = sc1_num+1
sc1_price = sc1_price+15
Item1 = (f"Scrunchie1 {sc1_num} ${sc1_price}")
print(" Button3")
if button_4.collidepoint(mx, my):
if click:
sc2_num = sc2_num+1
sc2_price = sc2_price+15
Item2 = (f"Scrunchie2 {sc2_num} ${sc2_price}")
print(" Button4")
pygame.draw.rect(screen, Colour, button_3, 2)
pygame.draw.rect(screen, Colour, button_4, 2)
screen.blit((font3.render("Scrunchie1", True, (0,0,0))),(b3_x+20, b3_y+15))
screen.blit((font3.render("Scrunchie2", True, (0,0,0))),(b4_x+20, b4_y+15))
click = False
#update screen
pygame.display.update()
clock.tick(60)
def QUIT():
running = True
while running:
pygame.quit()
quit()
#run the main menu
Main_sales()
pygame.quit()
```