K
K
Karlyshev David2021-11-13 14:39:11
Python
Karlyshev David, 2021-11-13 14:39:11

Why do I have to type Enter to keep the program running?

I am making a program to play music, but for some reason it asks to enter Enter in order to continue executing the code

def soundplay():
    playsound(directory)
        

def processing_bar():
    for i in tqdm(range(infomp32), ascii=True, desc=play):
        sleep(1)
        


p1, p2 = Thread(target=processing_bar), Thread(target=soundplay)
p2.start()    
p1.start()
    #Вот здесь почему-то появляется пустая строка и до тех пор пока ты не нажмёшь Enter цикл не запуститься
while 1:
    vopros = input("Хотите ли вы что-нибудь послушать? (д/н) ")
    if vopros == "д":
        xren()
    elif vopros == "н":
        break

How to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shurshur, 2021-11-13
@shurshur

Because input considers Enter to be the end of input. Until you press Enter, it waits for input.
Here we need an analogue of getch in DOS / Windows, here is an example of a module that implements this https://github.com/joeyespo/py-getch

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question