python win32api.LoadKeyboardLayout(), doesnt change language in IDLE shell?

筅森魡賤 提交于 2019-12-11 02:04:20

问题


Can someone help me out please...I'm trying to start my first programming project. It will be implemented in python.

I need to have a textbox (which i am using wxpython for). If the user enters any text into this text box, then I want it to appear as arabic. I wanted to this by automagically changing the users Keyboard to an arabic layout when the cursor lands in the given text box.

So i found this pywin32 module, which has a function LoadKeyboardLayout() So i am trying to test this in IDLE, to see if I can make it accept arabic text into IDLE, to see if it works. So I enter, into IDLE:

win32api.LoadKeyboardLayout('00000401',1)

This then returns, 67175425, the decimal equivalent of hex:'4010401' whcih I believe is the locale ID for Arabic. SO I think wow! I've done it, but when I try typing after this, in the IDLE window, it continues to type normal english characters.

Can someone please explain my errors and guide me towards a good solution.


UPDATE

Okay, I've been trying to solve this problem ever since posting the damn question. No luck. Then, I thought, "ok, screw it, instead of testing it quicly in IDLE, I will just try it out, in situ, in my source code for the project." WTF - it worked first time, giving exact behaviour that I wanted. Then I tried it in a different IDE, in the interpreted window, and again, IT WORKED straight away!

So clearly my issue is with IDLE, in its interpreting mode. Can anyone explain why it doesn't work in the IDLE shell???


回答1:


  1. Keyboard layout setting in Windows is per-process (and inherited from the parent process)
  2. IDLE runs your Python script in a background process separate from its GUI

So you have successfully changed the keyboard layout of the background Python process that is running your script, but not of IDLE's GUI.



来源:https://stackoverflow.com/questions/6725041/python-win32api-loadkeyboardlayout-doesnt-change-language-in-idle-shell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!