Hi - me again, haha!
I found a button class I understand - this one - but now I've encountered a problem. When a button is clicked, I want it to run a function that opens a new screen. However, the new function only runs whilst I'm keeping hold of the mouse. I could fix it by making the button set something to true which would then run the function, however now that I am using a function, it won't work and none of us here can figure out why. Any help?
This is where I've first tried to use the classes. I put the 'if clicked == False' to get the original screen to stop showing when a function is run - in each function, it sets clicked to True at the beginning - but now it still doesn't work. Any help?
If you need more of the code to be able to help, is there any chance I could send you it via PM? I don't particularly want to post my entire project code so far online but I know this might not be enough for you to be able to help. Thanks!
I found a button class I understand - this one - but now I've encountered a problem. When a button is clicked, I want it to run a function that opens a new screen. However, the new function only runs whilst I'm keeping hold of the mouse. I could fix it by making the button set something to true which would then run the function, however now that I am using a function, it won't work and none of us here can figure out why. Any help?
This is where I've first tried to use the classes. I put the 'if clicked == False' to get the original screen to stop showing when a function is run - in each function, it sets clicked to True at the beginning - but now it still doesn't work. Any help?
# MAIN GAME LOOP while done == False: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True if clicked == False: print("opened") print(clicked) screen.fill(WHITE) # initialising all buttons teacherLogin = Button((100, 250, 400, 100), teacherChoice, text = 'Teacher') studentLogin = Button((100, 100, 400, 100), letterButton, text = 'Student', colour = BLUE) teacherLogin.getEvent() teacherLogin.draw(screen) studentLogin.getEvent() studentLogin.draw(screen) print("drew buttons") screen.blit(loginMessage, [100, 10]) print("showed title") pygame.display.update() elif clicked == True: print("clicky") print(teacherLogin.function) pygame.quit()It doesn't run the 'clicky' bit which should run after clicked becomes true either.
If you need more of the code to be able to help, is there any chance I could send you it via PM? I don't particularly want to post my entire project code so far online but I know this might not be enough for you to be able to help. Thanks!