pythonwindowsuser-interfacekivyime

How to activate IME select panel on windows when a Kivy TextInput got focus


My os is windows10 Chinese version. for input Chinese charactor, I use an IME to select word, like this: Input in google page

but on a Kivy application, the Textinput widget can not activate IME select panel. for example, when i run the login demo from Kivy:

from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput


class LoginScreen(GridLayout):

    def __init__(self, **kwargs):
        super(LoginScreen, self).__init__(**kwargs)
        self.cols = 2
        self.add_widget(Label(text='User Name'))
        self.username = TextInput(multiline=False)
        self.add_widget(self.username)
        self.add_widget(Label(text='password'))
        self.password = TextInput(password=True, multiline=False)
        self.add_widget(self.password)


class MyApp(App):

    def build(self):
        return LoginScreen()


if __name__ == '__main__':
    MyApp().run()

The app screen is:

Input in Kivy app

No IME select panel popup. What i expect is:

Expected input in Kivy app

I searched doc from Kivy homepage, all IME related pages are about mobile device, not windows.

Please help.


Solution

  • Finally, i change the source code of SDL2, and compile a new dll to fix it. sure it's not a good solution, but the only i've found.

    1. download SDL2 source code here: libsdl.org

    2. find a file named "SDL_windowskeyboard.c", open it, add a macro definition: change source file of SDL2

    3. rebuild it, make sure choose the correct platform(win32 or x64), then copy generated dll to overwrite the original one. In my project, the sdl package is in venv envirement "venv\share\sdl2\bin"