Python Forum
Problem with pygame.event.clear
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with pygame.event.clear
#1
I use pygame to design a psychophysical experiment. The general flow of the experiment is that two objects appear in each trial, then press the left and right direction keys to select one of them, the system will inform the result, and then make the next trial. Now I have found such a problem: when running on some computers, if I press the left and right keys multiple times in one trial, the event queue should be cleared before the next selection when running on the normal computer, and the results should be given after the selection on this trial, which is also true on my personal laptop(the next selection will not be affected by pressing multiple times); However, on some computers, when running the same program, it will execute the selection of the next few times in sequence according to the sequence of pressing keys (it will automatically select according to the sequence about key without making a selection). In addition, even if the program is encapsulated with pyinstaller on the normal computer, the problem will still occur when the encapsulated program used on the problematic computer. How can I solve it?

Here is the program segment. If you need to run the total program, I will provide it with you.
        # wait for a click
        def wait4click(duration=1500):
            left = (WIN_LENGTH / 4 - IMG_HEIGHT / 2, WIN_WIDTH / 2 - IMG_WIDTH / 2)
            right = (3 * WIN_LENGTH / 4 - IMG_HEIGHT / 2, WIN_WIDTH / 2 - IMG_WIDTH / 2)
            pygame.event.clear()
            t_start = pygame.time.get_ticks()
            while True:
                t_now = pygame.time.get_ticks()
                if t_now - t_start > duration:
                    return 'BLANK'
                else:
                    for event in pygame.event.get():
                        if event.type == KEYDOWN:

                            if event.key == K_LEFT:
                                choice = 'left'
                                pygame.draw.polygon(win, red, [eval(choice),
                                                               (eval(choice)[0] + IMG_HEIGHT, eval(choice)[1]), (
                                                                   eval(choice)[0] + IMG_HEIGHT,
                                                                   eval(choice)[1] + IMG_WIDTH),
                                                               (eval(choice)[0], eval(choice)[1] + IMG_WIDTH)], 10)
                            elif event.key == K_RIGHT:
                                choice = 'right'
                                pygame.draw.polygon(win, red, [eval(choice),
                                                               (eval(choice)[0] + IMG_HEIGHT, eval(choice)[1]), (
                                                                   eval(choice)[0] + IMG_HEIGHT,
                                                                   eval(choice)[1] + IMG_WIDTH),
                                                               (eval(choice)[0], eval(choice)[1] + IMG_WIDTH)], 10)
                            elif event.key in [K_ESCAPE]:
                                resp = pygame.key.name(event.key)
                                pygame.event.clear()
                                return resp
                            else:
                                continue
                            pygame.event.clear()
                            return choice

        train_list = ['p1', 'p1', 'p2', 'p2', 'p2', 'p2', 'p1', 'p1']
        for i in range(len(train_list)):
            [correct_cue_loc, wrong_cue_loc] = draw_cue(train_list[i], introduction=True, symbol=True)  # draw two objects
            subj_choose = wait4click(duration=1500)
            break_signal = train_judgement(subj_choose)  # judge and show the result on the screen
            if break_signal:
                break
            pygame.time.wait(1000)
            fadeout()    # equal to win.fill(grey),[output][/output] pygame.display.update()
            text_msg('+')
            pygame.time.wait(1000)
            win.fill(grey)
Reply


Messages In This Thread
Problem with pygame.event.clear - by qq12346 - Jan-25-2022, 05:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pygame double jump problem Yegor123 3 2,649 May-02-2023, 09:34 PM
Last Post: sudoku6
  (HELP GREATLY APPRECIATED) New user- Huge Pygame Installation Problem! Jbomb 1 2,877 Jan-12-2021, 07:32 PM
Last Post: MK_CodingSpace
  problem with pygame Aladdin 3 4,270 Jun-25-2020, 01:41 PM
Last Post: Aladdin
  Problem with music - Pygame.error GaseBall 1 3,240 Nov-28-2019, 07:46 PM
Last Post: SheeppOSU
  [PyGame] Rotation Problem in PyGame thunderbird028 1 2,739 Nov-14-2019, 06:49 AM
Last Post: Windspar
  [PyGame] Pong game key.event problem erickDarko 2 4,241 Dec-12-2018, 03:17 PM
Last Post: erickDarko
  My Pygame Project's Problem **huh** osmanb06 2 3,714 Nov-06-2018, 09:27 AM
Last Post: osmanb06
  Coding problem in a Pygame Sghet 4 8,100 Aug-13-2018, 05:39 PM
Last Post: MTGReen
  [PyGame] Problem importing pygame / installing pygame Klar 4 9,339 Dec-16-2017, 05:48 PM
Last Post: Klar
  Importing pygame Mac problem Benjipincus 1 3,110 Dec-16-2017, 01:54 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020