Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1251

Python • KeyboardInterrupt in While True statement

$
0
0
I have a program that starts with an image. When a button is pressed, a video plays, then when the video is over, it loops back to the original image. This is for a display room so I want this to continually run, unless I stop it. However, my "except KeyboardInterrupt" is not responding. Do I need to place it in a different spot for it to catch it?

Code:

try:        while True:                        led.off()                        # call the image method                        image("elevator.jpg")                        while(button.is_pressed == False):                                pass                        led.on()                        time.sleep(2)                        # call the video method                        video("handshake1080.mp4")                        led.off()except KeyboardInterrupt:        quit()

Statistics: Posted by alfordtp — Sun Jan 19, 2025 4:35 pm



Viewing all articles
Browse latest Browse all 1251

Trending Articles