PySimpleGUI / PySimpleGUI

Python GUIs for Humans! PySimpleGUI is the top-rated Python application development environment. Launched in 2018 and actively developed, maintained, and supported in 2024. Transforms tkinter, Qt, WxPython, and Remi into a simple, intuitive, and fun experience for both hobbyists and expert users.
https://www.PySimpleGUI.com
Other
13.36k stars 1.84k forks source link

[ Enhancement/Bug/Question] NOTE - you can also call sg.main() or sg.main_open_github_issue() to post an issue #6796

Closed shields1968 closed 1 month ago

shields1968 commented 1 month ago

Operating System Win 10

PySimpleGUI Port tkinter

Versions (NOTE - PSG4 is no longer supported) Version information can be obtained by calling sg.main_get_debug_data() Or you can print each version shown in ()

Python version (sg.sys.version) '3.8.19 (default, Mar 20 2024, 19:55:45) [MSC v.1916 64 bit (AMD64)]'

PySimpleGUI Version (sg.version) 4.60.3

GUI Version (tkinter (sg.tclversion_detailed), PySide2, WxPython, Remi) GUI Version (tkinter (sg.tclversion_detailed), PySide2, WxPython, Remi) Priority Support Code (Commercial License Users) Your Experience In Months or Years (optional) Years Python programming experience

hobby

Years Programming experience overall

hobby Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine)

Not

Anything else you think would be helpful?



Troubleshooting

These items may solve your problem. Please check those you've done by changing - [ ] to - [X]

Detailed Description

Hello I have a question, I have a small program that opens based on events, which is fine but I want the user to not be able to close it unless it is for something in particular. So far it works fine, but when the user uses the Alt + F4 keys, it closes and gives the following error: bad window path name ".!toplevel2" Is there a way to control this? Could it be to disable the button or buttons mentioned so that they cannot use them?

Thank you very much

Code To Duplicate

layout = [  [sg.Text('Ud. no solicito autoriazcion para llevarse este equipo.    Nombre: '+ str(nombre_equipo), justification='center', font='arial 22', size=(70,1), text_color='red')],
            [sg.Text('Ingresar codigo de desbloqueo:'), sg.InputText(key='INPUT_0', disabled  =  activ)],
            [sg.Text('', justification='center', font='arial 22', key='men', size=(70,1), text_color='red')],
            [sg.Text('', size=(40,1)),sg.ProgressBar(5, 'h', size=(50,20), k='-PROG-', visible = False)],

            #[sg.Button('Cancel')]]
            []]

# Create the Window
window = sg.Window('Window Title', layout, finalize=True, keep_on_top=True, no_titlebar = True)
for i in range(0, 1):
        element = window['INPUT_' + str(i)]
            # Bind 'ENTER' key to elements
        element.bind("<Return>", "_ENTER")
            # Bind 'FocusIn' to elements to select all when get focus
        element.bind('<FocusIn>', "_FOCUS")

# Event Loop to process "events" and get the "values" of the inputs
while True:

    window.maximize()
    event, values = window.read()

    if event == 'INPUT_0_ENTER':
        if str (values['INPUT_0']) == str(codauriza):
            guardalog( 'Desbloqueando equipo por codigo ')
            mensajes('Desbloqueando equipo')
            window['-PROG-'].update(visible=True)
            time.sleep(1)
            window['-PROG-'].update(int(1))
            window.refresh()
            time.sleep(1)
            window['-PROG-'].update(int(2))
            window.refresh()
            time.sleep(1)
            window['-PROG-'].update(int(3))
            window.refresh()
            mensajes('Ya casi terminando')
            time.sleep(1)
            window['-PROG-'].update(int(4))
            window.refresh()
            time.sleep(1)
            window['-PROG-'].update(int(5))
            window.refresh()
            time.sleep(0.5)
            tiempo = tiempo2
            break

        elif str (values['INPUT_0']) == str(codmaestro):
            guardalog( 'Desbloqueando equipo por codigo Maestro')
            mensajes('Desbloqueando equipo')
            window['-PROG-'].update(visible=True)
            time.sleep(1)
            window['-PROG-'].update(int(1))
            window.refresh()
            time.sleep(1)
            window['-PROG-'].update(int(2))
            window.refresh()
            time.sleep(1)
            window['-PROG-'].update(int(3))
            window.refresh()
            mensajes('Ya casi terminando')
            time.sleep(1)
            window['-PROG-'].update(int(4))
            window.refresh()
            time.sleep(1)
            window['-PROG-'].update(int(5))
            window.refresh()
            time.sleep(0.5)
            tiempo = tiempo2
            break

        else:
            mensajes('Codigo NO Valido: ')
            window['INPUT_0'].set_focus()
            window['INPUT_0'].update(select=True)

window.close()

A short program that isolates and demonstrates the problem (Do not paste your massive program, but instead 10-20 lines that clearly show the problem)

This pre-formatted code block is all set for you to paste in your bit of code:



# Paste your code here

    layout = [  [sg.Text('Ud. no solicito autoriazcion para llevarse este equipo.    Nombre: '+ str(nombre_equipo), justification='center', font='arial 22', size=(70,1), text_color='red')],
                [sg.Text('Ingresar codigo de desbloqueo:'), sg.InputText(key='INPUT_0', disabled  =  activ)],
                [sg.Text('', justification='center', font='arial 22', key='men', size=(70,1), text_color='red')],
                [sg.Text('', size=(40,1)),sg.ProgressBar(5, 'h', size=(50,20), k='-PROG-', visible = False)],

                #[sg.Button('Cancel')]]
                []]

    # Create the Window
    window = sg.Window('Window Title', layout, finalize=True, keep_on_top=True, no_titlebar = True)
    for i in range(0, 1):
            element = window['INPUT_' + str(i)]
                # Bind 'ENTER' key to elements
            element.bind("<Return>", "_ENTER")
                # Bind 'FocusIn' to elements to select all when get focus
            element.bind('<FocusIn>', "_FOCUS")

    # Event Loop to process "events" and get the "values" of the inputs
    while True:

        window.maximize()
        event, values = window.read()

        if event == 'INPUT_0_ENTER':
            if str (values['INPUT_0']) == str(codauriza):
                guardalog( 'Desbloqueando equipo por codigo ')
                mensajes('Desbloqueando equipo')
                window['-PROG-'].update(visible=True)
                time.sleep(1)
                window['-PROG-'].update(int(1))
                window.refresh()
                time.sleep(1)
                window['-PROG-'].update(int(2))
                window.refresh()
                time.sleep(1)
                window['-PROG-'].update(int(3))
                window.refresh()
                mensajes('Ya casi terminando')
                time.sleep(1)
                window['-PROG-'].update(int(4))
                window.refresh()
                time.sleep(1)
                window['-PROG-'].update(int(5))
                window.refresh()
                time.sleep(0.5)
                tiempo = tiempo2
                break

            elif str (values['INPUT_0']) == str(codmaestro):
                guardalog( 'Desbloqueando equipo por codigo Maestro')
                mensajes('Desbloqueando equipo')
                window['-PROG-'].update(visible=True)
                time.sleep(1)
                window['-PROG-'].update(int(1))
                window.refresh()
                time.sleep(1)
                window['-PROG-'].update(int(2))
                window.refresh()
                time.sleep(1)
                window['-PROG-'].update(int(3))
                window.refresh()
                mensajes('Ya casi terminando')
                time.sleep(1)
                window['-PROG-'].update(int(4))
                window.refresh()
                time.sleep(1)
                window['-PROG-'].update(int(5))
                window.refresh()
                time.sleep(0.5)
                tiempo = tiempo2
                break

            else:
                mensajes('Codigo NO Valido: ')
                window['INPUT_0'].set_focus()
                window['INPUT_0'].update(select=True)

    window.close()

#### Screenshot, Sketch, or Drawing

---------------------

### Watcha Makin?

If you care to share something about your project, it would be awesome to hear what you're building.
pysimpleissue[bot] commented 1 month ago

The PySimpleGUI GitHub Issues bot has determined there is a problem with your Issue's form.

Please fix the problems by editing the first comment or the title and then reopen your issue to have it checked again.

More detailed information:

Title must be ONE of: Bug Question Enhancement Error