N
N
nemoigollos2020-05-18 18:18:48
Python
nemoigollos, 2020-05-18 18:18:48

Why does the program window hang when the loop starts?

What is the problem?! When I start and press button 1, the cycle starts and because of this the program window hangs to all buoys, but the cycle itself works until the program is killed, closed. Why does it hang where I messed up the shit?
Here is the code

import PySimpleGUI as sg
import keyboard
import time

def BS():
    while True:
        if keyboard.is_pressed('space'):
            while keyboard.is_pressed('space'):
                keyboard.press_and_release('space')
                time.sleep(1.03)

        else:
            pass


layout = [[sg.Button('1'), sg.Button('2'), sg.Exit()] ]

window = sg.Window('Test').Layout(layout)

while True:
    event, values = window.Read()
    if event in (None, 'Exit'):
        break
    if event == '1':
        BS()
    elif event == '2':
        pass
window.Close()

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
L
Lander, 2020-05-18
@usdglander

When you start the loop, the window's system message handler stops working, because it does not receive control. Study the OS architecture and event model in order to implement such things correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question