I’m quite struggling on integrating a virtual keyboard on my python app.
These are the virtual keyboard I tried and my problems on each one.
I’m on Raspberry Pi OS Bookworm on a Raspberry Pi 5.
matchbox-keyboard
On this keyboard I got an extremely strange bug that happened when my app is in Fullscreen mode (Need to clic 1 time with a mouse on the virtual keyboard).
This bug also occur when a popup is showed, the user cannot click ok
with the touch screen but can close the popup.
This is a simple script where I replicated the bug:
import tkinter as tk
import subprocess
import psutil
def open_virtual_keyboard(event):
global keyboard_process
if keyboard_process is None or keyboard_process.poll() is not None:
keyboard_process = subprocess.Popen(['matchbox-keyboard'])
root.after(100, lambda: event.widget.focus_force())
print("Opening a virtual keyboard")
def close_virtual_keyboard(event=None):
global keyboard_process
root.after(100, check_focus)
print("Closing the virtual keyboard")
def check_focus():
global keyboard_process
focused_widget = root.focus_get()
if not isinstance(focused_widget, tk.Entry):
if keyboard_process is not None:
keyboard_process.terminate()
keyboard_process = None
def on_closing():
close_virtual_keyboard()
for proc in psutil.process_iter(['name']):
if proc.info['name'] == 'matchbox-keyboard':
proc.terminate()
root.destroy()
def handle_click(event):
if not isinstance(event.widget, tk.Entry):
close_virtual_keyboard()
keyboard_process = None
root = tk.Tk()
root.title("Virtual keyboard App")
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
# BUG
root.attributes("-fullscreen", True)
root.geometry(f"{screen_width}x{screen_height}")
root.update()
# BUG
entry1 = tk.Entry(root)
entry1.pack(padx=10, pady=10)
entry2 = tk.Entry(root)
entry2.pack(padx=10, pady=10)
for entry in (entry1, entry2):
entry.bind("<FocusIn>", open_virtual_keyboard)
entry.bind("<FocusOut>", close_virtual_keyboard)
root.bind("<Button-1>", handle_click)
root.protocol("WM_DELETE_WINDOW", on_closing)
root.mainloop()
wvkbd-mobintl
When my app is in Fullscreen mode I don’t manage to bring the virtual keyboard to the front. Even thought I tried a lot of things with xdotool
and other tools.
onboard
I don’t manage to show the keyboard and hide it, I tried with dbus-send
.
Noy. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.