Home > Net >  PySimpleGUI one_line_progress_meter does not return False when pressing X on Windows
PySimpleGUI one_line_progress_meter does not return False when pressing X on Windows

Time:12-19

In the docs of PySimpleGUI it is stated that the function returns true if either the cancel button is pressed or the X button in the windows titlebar. However, it is only working for the Cancel button in version 4.55.1.

MWE:

import time
import PySimpleGUI as sg

for i in range(1, 200):
    time.sleep(0.1)
    if not sg.one_line_progress_meter(title="test", current_value=i, max_value=200,
                                      no_button=False):
        print('returned false')
        break

Am I missing something?

CodePudding user response:

For the window of sg.one_line_progress_meter, it is defined as disable_close=True, so this window cannot be closed by clicking Close button of window, Only Cancel button work for it.

OK, following code show the hack way

  • Find the window for one_line_progress_meter
  • Set the attribute DisableClose of quick-meter window to False
import time
import PySimpleGUI as sg

sg.one_line_progress_meter(title="test", current_value=0, max_value=200, no_button=False)
key='OK for 1 meter'
meter = sg.QuickMeter.active_meters[key]
meter.window.DisableClose = False

for i in range(1, 200):
    time.sleep(0.1)
    if not sg.one_line_progress_meter(title="test", current_value=i, max_value=200, no_button=False):
        print('returned false')
        break

sg.one_line_progress_meter_cancel()
  • Related