在Tkinter中使用屏幕键盘上的文本更新条目小部件 [英] Updating entry widget using text from onscreen keyboard in tkinter

查看:76
本文介绍了在Tkinter中使用屏幕键盘上的文本更新条目小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在具有触摸屏的raspberry pi上运行我的代码.GUI是使用Tkinter制作的,当输入焦点时,我想弹出系统屏幕键盘.这是我当前的代码:

I want to run my code on raspberry pi which has a touchscreen attached to it. The GUI is made using Tkinter and I want to pop up the system onscreen keyboard when the entry is focused. Here is my current code:

用于将条目窗口小部件与FocusIn事件绑定:

For binding the entry widget with FocusIn event:

self.usernameEntry.bind('<FocusIn>', self.FocusLogin)

用于调用pi中安装的屏幕键盘:

For calling the onscreen keyboard installed in the pi:

    def FocusLogin(self,event):
       os.system('florence')

我的问题是,无论我通过佛罗伦萨键盘输入什么,它都不会自动填充输入小部件.只有在关闭键盘后,我才能真正看到键入的内容.我尝试过使用matchbox-keyboard,但它只会冻结整个UI.佛罗伦萨似乎更好,但它并没有像我提到的那样更新输入字段.我希望用户界面在输入字段中自动显示我按下的键.

My problem is that whatever I enter through florence keyboard it never automatically populates the entry widget. It is only after I close the keyboard that I actually see what I typed in. I've tried matchbox-keyboard but it just freezes the whole UI. Florence seems better but it does not update the entry field as I mentioned. I want the UI to automatically show the keys I'm pressing in the entry field.

推荐答案

对于寻找答案的人,我发现了两种解决方法:

For someone looking for the answer, I found 2 ways of solving this:

首先,使用subprocess.popen创建UI和Keyboard的单独线程.在机载键盘上可以正常工作,但佛罗伦萨会滞后

First, use subprocess.popen to create seperate threads of UI and the Keyboard. This works fine on onboard keyboard but florence lags

第二种方法是在打开应用程序之前在后台运行佛罗伦萨.然后使用

Second method is to run florence in background before opening the app. Then use

florence hide
florence show

隐藏或显示要绑定的事件上的佛罗伦萨.

to hide or display florence on the events you want to bind.

这篇关于在Tkinter中使用屏幕键盘上的文本更新条目小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆