How to use the Gtk.IMContext.activate_osk() function?

I have a Gtk4 Python application and I want to use an on screen keyboard in cases where no physical keyboard is attached to the system

I found the function Gtk.IMContext.activate_osk() function, but I found no examples on how to use it in a Python program.

Any help, pointers to examples, is much appreciated.

You don’t need to do anything: GTK will automatically ask the input method raise the OSK (if one is available) when giving focus to a text entry.

The IMContext.activate_osk() method is only relevant if you’re implementing your own text widget without using GtkText—something we do not recommend.

Ok, I see, thank you. Is there a way to override the standard behaviour, i.e. to have a OSK popup even if physical keyboard is connected (for test/debugging)?

And, can the OSK be prevent on a per-entry base? I am asking because I develop touchscreen software that has Entries that are “fed” by a grid of buttons (like a calculator), so I do not want to pop-up an OSK if I tap into the entry field. Otoh I have some Entries that do not have this “software keyboard”, so there I want the OSK to appear.

Hi,

Use the Gtk.Entry:input-hints property ans set the INHIBIT_OSK flag.

Thank you! I will try this.

1 Like