mercredi 30 mai 2018

Uncheck radio-button

So I'm quite new to programming in Python (I'm a highschooler) and I have this project where I need to have radio buttons in Pygame. The software that I'm creating is a calendar/reminder. So I created my own custom radio button on Illustrator instead of generating one from code from scratch. I have a blank radio button and on top of it, after clicking, an image of a checkmark appears like a real radio button except for its just an image. So far so good. But then I want it to disappear after I re-click on it. I can't find a way to do so. After I blit the picture what do I need to do to un-blit it? Here's the code (the pictures are on my computer):

import pygame as pg
import sys
import time

pg.init()

screen = pg.display.set_mode((600, 600))
picture = pg.image.load('light_gaussian_blur.jpg').convert()
picture = pg.transform.scale(picture, (600, 600))
rect = picture.get_rect()
screen.blit(picture, rect)

cal=pg.image.load('calendar_dos.png').convert_alpha()
cal=pg.transform.scale(cal, (450, 450))
screen.blit(cal,(80,83))

tick = pg.image.load('tick_red.png').convert_alpha()
tick = pg.transform.scale(tick, (25, 25))

pg.display.flip()

while True:
        for e in pg.event.get():
                if e.type == pg.QUIT:
                        pg.quit()
                        sys.exit()
                if e.type == pg.MOUSEBUTTONDOWN:
                        mx, my = pg.mouse.get_pos()
                        if my > 234 and my < 257:
                                if mx > 134 and mx < 154:
                                        screen.blit(tick,(132,237))
                        if my > 277 and my < 296:
                                if mx > 134 and mx < 154:
                                        screen.blit(tick,(132,275))
                        if my > 319 and my < 337:
                                if mx > 134 and mx < 154:
                                        screen.blit(tick,(132,314))
                        if my > 358 and my < 375:
                                if mx > 134 and mx < 154:
                                        screen.blit(tick,(132,354))
                        if my > 399 and my < 417:
                                if mx > 134 and mx < 154:
                                        screen.blit(tick,(132,398))
                        if my > 441 and my < 459:
                                if mx > 134 and mx < 154:
                                        screen.blit(tick,(132,438))
        time.sleep(0.03)
        pg.display.update()




Aucun commentaire:

Enregistrer un commentaire