lundi 17 mai 2021

The If Doesn't Work in While true Loop in Python [closed]

Hi Everyone I have a problem with my code I can't get That if Works in The While Loop And I want to This If Be a Loop and Always Wait for me to press the key And I tried with 100 times and didn't work So Please Help me

from PIL import Image
import os
import time
import random
import keyboard
from playsound import playsound
hotkey = "f"
while True:
    for i in range(0,100000):
        if keyboard.is_pressed(hotkey):
          print("Hotkey is being pressed")
          os._exit(0)
          time.sleep(0.05)
          time.sleep(0.01)
        pic0 = 'Z:/1.jpg'
        pic1 = 'Z:/2.jpg'
        pic2 = 'Z:/3.jpg'
        pic3 = 'Z:/7.jpg'
        pic4 = 'Z:/8.jpg'
        pic5 = 'Z:/9.jpg'
        pic6 = 'Z:/12.jpg'
        pic7 = 'Z:/13.jpg'
        pic8 = 'Z:/File_000.jpeg'
        ran = random.choice([pic0, pic1, pic2, pic3, pic4, pic5, pic6, pic7, pic8])
        time.sleep(60)
        im = Image.open(ran)
        soundfile = "C:/dig.wav"
        playsound(soundfile)
        im.show()
        #time.sleep(1)
        print(i)
        os.system("TASKKILL /F /IM Microsoft.Photos.exe")

Aucun commentaire:

Enregistrer un commentaire