问题描述
您好,我在使用 kivy 的 textinput 小部件的 input_type 属性时遇到问题.问题是我做了两个自定义文本输入,一个称为 StrText,我在其中设置 input_type = 'text'.然后是第二个名为 NumText 的文本输入,input_type = 'number'.我使用 kivy 启动器在我的手机上对此进行了测试,并注意到一旦我点击 NumText 输入,它会带来一个数字键盘,如果我点击 StrText,它会带来相同的数字键盘而不是普通的文本键盘.如果你稍微玩一下,你会发现大部分时间都会返回数字键盘.请问我的代码有问题吗,或者我该如何解决?你会在下面找到我的代码
Hi im having issues with using the input_type property of kivy's textinput widget. The thing is i made two custom text input one i called StrText where i set input_type = 'text'. Then a second text input named NumText with input_type = 'number'. I tested this on my phone using kivy launcher, and noticed that once i tap on the NumText input and it brings a number keyboard, if i tap on the StrText, it brings the same number keyboard instead of a normal text keyboard. If you play with it a little you'll notice mostly number key board is returned most of the time. Please is there something wrong with my code, or how can i fix this? You'll find my code below
main.py
from kivy.app import App
from kivy.uix.bubble import Bubble
from kivy.core.window import Window
class BubbleApp(App):
pass
if __name__ == '__main__':
Window.fullscreen = False
BubbleApp().run()
bubble.kv
GridLayout:
cols: 1
StrText:
height: '48dp'
size_hint_y: None
Label:
text: 'Number keyboard below'
height: '48dp'
size_hint_y: None
multiline: False
font_size: self.height * .5
NumText:
height: '48dp'
size_hint_y: None
<StrText@TextInput>:
input_type: 'text'
multiline: False
font_size: self.height * .5
<NumText@TextInput>:
input_type: 'number'
input_filter: 'int'
multiline: False
font_size: self.height *.5
推荐答案
最近我在使用 Kivy1.10.0 构建我的应用程序时遇到了类似的问题.我在 android 中使用了默认的键盘应用程序,但它仍然不断地从 Numeric Keypad 更改为 Text Keypad.
Recently I faced similar issue when I built my App using Kivy1.10.0. I used the default keyboard app in android but still it was keep changing from Numeric Keypad to Text Keypad.
这次我尝试使用 kivy==1.9.1 和 Cython==0.23.1 和 buildozer==0.32 来构建 .apk,它对我有用.
This time I tried kivy==1.9.1 with Cython==0.23.1 and buildozer==0.32 to build the .apk and it worked for me.
注意:
我建议创建一个 virtualenv 来安装上面的特定包并使用它来创建 .apk 文件.
I suggest to create a virtualenv to install above specific packages and use it to create the .apk file.
virtualenv build32env
source build32env/bin/activate
pip install buildozer==0.32 Cython==0.23.1
执行 buildozer init
后,确保更改 buildozer.spec
文件:
After executing buildozer init
make sure to change buildozer.spec
file:
来自
requirements = kivy
到
requirements = kivy==1.9.1
否则它将使用最新的 kivy 版本来构建 .apk 文件.
otherwise it will use the latest kivy version to build the .apk file.
更多关于 buildozer 的细节
希望对他人有所帮助!
这篇关于使用 kivy textinput 的 'input_type' 属性的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!