Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13981

Pygame buttons clicks and if statments

$
0
0

I've just started again after a while and having some issues and a little lost.

Have been trying to make menus in pygame using images as buttons. Fuigured most of it out after looking at others but think I'm making a silly mistake and can't figure it out - chopped & changed alot of lines.The first button works and sends you to the correct menu but none of the others register.

Most guides use draw to create buttons, so haven't been helpful.

Similar but uses draw

Have tried moving my IF \ ELIF \ ELSE statements around but get errors or nothing works.

Not really a coder, just wanted something to hold our D&D homebrew together - use TKinter before but thought I'd have a go at this.

import pygamefrom pygame import mixerpygame.init()width=900;height=800screen = pygame.display.set_mode( (width, height ) )pygame.display.set_caption('Chapter 1')#TownMap = pygame.image.load("Data/images/town.png").convert()#Button = pygame.image.load("Data/images/buttonsSolo.png").convert_alpha()def Main_Menu():    Back_Drop = pygame.image.load("Data/images/Art/cursewick1.jpg").convert()  Start_Button = pygame.image.load("Data/Images/UI/Buttons/Start.png").convert_alpha()   Help_Button = pygame.image.load("Data/Images/UI/Buttons/Help.png").convert_alpha()   Exit_Button = pygame.image.load("Data/Images/UI/Buttons/Exit.png").convert_alpha()   screen.blit(Back_Drop, (0,0))  screen.blit(Start_Button ,  ( 10,10)) # paint to screen  screen.blit(Help_Button ,  ( 10,110)) # paint to screen  screen.blit(Exit_Button ,  ( 10,210)) # paint to screen  pygame.display.flip() # paint screen one time  mixer.init()  mixer.music.load("Data\Audio\Music\Intro.mp3")  pygame.mixer.music.set_volume(0.1)  mixer.music.play()  running = True  while (running):        for event in pygame.event.get():          if event.type == pygame.QUIT:              running = False          if event.type == pygame.MOUSEBUTTONDOWN:              # Set the x, y postions of the mouse click              x, y = event.pos              if Start_Button.get_rect().collidepoint(x, y):                  print('clicked on image')                  pygame.mixer.music.pause()                  Town_Map()              if Help_Button.get_rect().collidepoint(x, y):                  print('Help')                  pygame.mixer.music.pause()  #loop over, quite pygame  pygame.quit()

Viewing all articles
Browse latest Browse all 13981

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>