I am trying to write a program in Python that will open a random video file on a keypress(for me F8). I am very new to coding and currently stuck. I got it to the point where I am not getting any errors but now the program is not sticking around. Not sure what to do next. My code:
import os
import keyboard
import string
import random
from openfile import openfile
path = r"C:\Users\Rudy\Videos\GIFS"
letter = string.ascii_letters
digit = string.digits
def keyboardPress():
mp3Select = random.choice(os.listdir(path))
keypress = str(path + "\\" + mp3Select)
while True:
if keyboard.is_pressed('F8'):
openfile(keypress)
break
def main():
while True:
try:
keyboardPress()
except:
pass
main()