1
votes

I am building a simple python script that runs functions that control the Unicorn HAT on the RPi. My Intention is to control this using mouse clicks.

while True:
    for event in pygame.event.get()
        print(event)
        if event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 1:
                if upRun or tRun == 1: #Cancel any scrollers
                    upRun = 0
                    tRun = 0
                n()
            elif event.button == 2:
                up()
            else:
                art()

On testing this I receive no output. Note I have called pygame.init() as required.

Polling all events results only in empty events.

1
Is this the way the indentation in your code looks? Because the indentation in your for loop is incorrect - C_Z_
Well catched. Yes the indentation is different, it currently runs fine. - Iceblue
Did you remember to set up display properties? If not, that's probably why (no display, no events) - jDo
Thanks jDo. Having tried that earlier to no success I ruled that out, but works now. - Iceblue
@Iceblue Ok, odd. Anyway, glad it works. - jDo

1 Answers

0
votes

Something tells me that you didn't set up any display properties. I could be wrong but this works for me:

import pygame

pygame.init()
screen = pygame.display.set_mode((800,600))

while True:
    for event in pygame.event.get():
        print(event)
        if event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 1:
                if upRun or tRun == 1: #Cancel any scrollers
                    upRun = 0
                    tRun = 0
                n()
            elif event.button == 2:
                up()
            else:
                art()