python - How to make interactive area around boxes? -


imagine picture of 4 boxes different colors. below code tried. know make other pictures pop when click on 1 of boxes (how mark area , read clicking later use). there easier way this?

a, b = 685, 227 c, d = 310, 203 w, z = 684, 518 k, l = 311, 518 x, y = 310, 200 ekraan.blit(background,(x,y))  while true:     in pygame.event.get():         pygame.display.flip()         if i.type == pygame.quit:             sys.exit()         elif i.type == pygame.mousebuttondown:             ma,mb = i.pos             mc,md = i.pos             mw,mz = i.pos             mk,ml = i.pos             if abs(ma-a)<379 , abs(mb-b)<319:                 ekraan.blit(green,(685,227))                 klickedbutton = green             elif abs(mc-c)<379 , abs(md-d)<319:                 ekraan.blit(red,(310,203))                 klickedbutton = red             elif abs(mw-w)<379 , abs(mz-z)<319:                 ekraan.blit(yellow,(684,518))                 klickedbutton = yellow             elif abs(mk-k)<379 , abs(mk-k)<319:                 ekraan.blit(blue,(311,518))                 klickedbutton = blue 

one improvement code put points @ beginning respective colors in list of tuples , rid of wall of elifs when checking events:

quadrants = [(685, 227, green),              (310, 203, red),              (684, 518, yellow),              (311, 518, blue)] x, y = 310, 200 ekraan.blit(background, (x, y))  while true:     in pygame.event.get():         pygame.display.flip()         if i.type == pygame.quit:             sys.exit()         elif i.type == pygame.mousebuttondown:             mx, = i.pos             x, y, color in quadrants:                 if abs(mx-x) < 379 , abs(my-y) < 319:                     ekraan.blit(color, (x, y))                     klickedbutton = color                     break 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -