Repository navigation
[Bug] Keyboard spontaneously stops entering text into PSG fields #6811
Description
Activity
Try following code to check if anything wrong.
import PySimpleGUI as sg layout = [ [sg.Input(key="-IN-")], [sg.Push(), sg.Button("Submit")], ] sg.Window("Title", layout).read(close=True)
if nothing wrong, maybe use your code and remove some code until this issue not happened.
It's better have code to demo your issue and/or a movie to demo what happened.I assume if you restart your program it works again, that it's not a permanent kind of problem once it starts. Or if you run a second PySimpleGUI program, that one works as expected.
I would try a different version of Python/tkinter. It sounds like a tkinter + Linux problem.
@jason990420, the code you posted runs for me without any issues. A more complicated version I made also runs without issues. Unfortunately, the program I am running is complex enough that removing some code until it works isn't feasible.
And @PySimpleGUI , you're correct on both assumptions.
Thanks both of you for replying. I am using tkinter 8.6, python 3.9, and AlmaLinux 9.4. Before I was using Centos7 with python 3.6 (don't remember the tkinter version) and did not see this problem. I'll try python 3.12 and see if it persists.
tkinter has a 3 number more detailed version that's available if you use:
print(sg.framework_version)
It's the more detailed number that we're looking for. On Windows, 8.6.12 is packaged with Python 3.11.
I am currently using tkinter 8.6.10 with python 3.9. I have tried running this with python 3.12 and tkinter 3.6.10, as well as inside conda environments with python 3.6 and 3.13, both of which used tkinter 8.6.14. The Centos7 setup I had was using tkinter 8.5 and python 3.6, but I don't know the third digit of the tkinter version as this OS was overwritten when I updated to Alma 9.
I have (finally) identified the trigger for the keyboard to stop working. It relates to alt-tabbing away from the window while it's doing something. Here is a script that replicates the issue:
import PySimpleGUI as sg from time import sleep layout = [[sg.Button("Open Window")], [sg.Input(s=10, key='Text')]] basewindow = sg.Window("My Amazing GUI", layout) event1, values1 = basewindow.read(timeout=10) def waiting_window(message): layout2 = [[sg.Text(message)]] window = sg.Window(message, layout2) event2, values2 = window.read(timeout=100) return window while True: event, values = basewindow.read() if event == 'Open Window': alttab = waiting_window(f"Alt tab back to the main window and wait for this to close") sleep(5) alttab.close() if event == sg.WIN_CLOSED: exit()
More or less, just do what it says. There are a number of ways you can alt tab and get the input to stop appearing. Simply clicking away from the GUI does not replicate the issue, only alt tabbing.
I have tested this on another Ubuntu system and the issue did not appear there using the above script. It also, interestingly, did not appear when I ssh'ed into the Alma9 system from the Ubuntu system and then ran the GUI program on Alma9 but displaying the window on Ubuntu.
This might still be a tkinter issue, but I would appreciate taking a look regardless to see if the error can be replicated on another system and any insight into what about the program is specifically the cause and how it could be worked around. Thanks!
Reacted by PySimpleGUINice job isolating this!!
My system blue-screened while testing it (crazy but true... I'm on Windows 10). I would have expected alt-tab to be more of a Windows-specific problem, but since Linux does a similar kind of switching operation it makes sense there could be a problem.
I'm guessing that XWindows is failing to inform tkinter when the window regains focus or tkinter is somehow losing track of focus. Does the cursor re-appear anywhere when you return to the window? Can you make a video of the whole process so we can see what a failure looks like? I've not been able to duplicate it.
Thanks for the help! Sorry for the slow reply - I restarted the PC on Tuesday while trying to make it possible to screen record and the reproducibility of the issue changed. It still occurs - the video I attached shows that - but it doesn't happen as consistently as it did last week.
The video is here. Apologies for the Trial Period warning, I have a developer key and when I tried to enter it I don't think it worked, and I can't figure out how to enter it now. In the video, it takes a few tries, but eventually it shows that I start clicking around but no text is entered. I am pressing the keyboard when this is happening, and I enter some text into the terminal to show that. I can still highlight text, move the cursor, and press buttons, but it's as if keypresses don't exist.
Thanks!
Hi, checking back in. Was the video helpful?
This seems specific to Alma. Can you try a tkinter program like this one assuming multiple windows are not a requirement. The problem looks like a tkinter specific issue and not a PySimpleGUI problem. It's highly specific to your environment as well. No one else has reported anything like it and we've tested on other Linux distros with no problems.
import tkinter as tk # Create the main window window = tk.Tk() window.title("Name Input") window.geometry("300x100") # Create a label for "Name" name_label = tk.Label(window, text="Name:", font=("Arial", 12)) name_label.pack(pady=10) # Create an entry field for input name_entry = tk.Entry(window, font=("Arial", 12), width=20) name_entry.pack() # Start the main event loop window.mainloop()
- addedPlatform Specific Issue - LinuxSpecific to the Linux environmentSpecific to the Linux environment
on Nov 19, 2024
Type of Issue (Enhancement, Error, Bug, Question)
Bug
Operating System
Alma Linux 9
PySimpleGUI Port (tkinter, Qt, Wx, Web)
tkinter
Versions (NOTE - PSG4 is no longer supported)
Python Interpeter: /usr/bin/python3
Python version: 3.9.18
Platform: Linux
Platform version: ('glibc', '2.34')
Port: PySimpleGUI
tkinter version: 8.6.10
PySimpleGUI version: 5.0.6
Priority Support Code (Commercial License Users)
n/a
Your Experience In Months or Years (optional)
Years Python programming experience: 8
Years Programming experience overall: 9
Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine) yes
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
I am running a GUI in Alma Linux 9 that interfaces with several classes I have written, which interface with several external systems. Sometimes, after the GUI has been in use for a bit, the keyboard spontaneously stops working. I have not been able to understand what causes this, nor been able to predict the issue. The keyboard still works in other windows, and I can still interact with the GUI in other ways (pressing buttons, etc.), so I believe it is an issue between PSG and the keyboard. I recently upgraded the operating system of the PC from Centos 7 to Alma 9; in Centos 7 this issue was not observed, and the code has not changed.
In debugging this, I have added
enable_events=Trueto a few of the text boxes and told the GUI to print every event it sees. I have also added the following block which runs a keyboard listener while the GUI event loop runs:When the keyboard issue I am discussing occurs, the events generated by buttons and checkboxes still appear in the terminal output, but no events generated by
sg.Inputfields show up. However, the listener I pasted above still prints all key presses and releases that occur while the GUI window is in focus, but no text is entered into the GUI and nosg.Inputevents appear.Code To Duplicate
I have not been able to understand nor isolate the issue, so I am not sure I can give duplication code. I know how helpful that is, but I am running out of ideas for how to solve this.
Thanks for any help you can provide!