問題描述
您好,我在使用 kivy 的 textinput 小部件的 input_type 屬性時遇到問題.問題是我做了兩個自定義文本輸入,一個稱為 StrText,我在其中設(shè)置 input_type = 'text'.然后是第二個名為 NumText 的文本輸入,input_type = 'number'.我使用 kivy 啟動器在我的手機上對此進行了測試,并注意到一旦我點擊 NumText 輸入,它會帶來一個數(shù)字鍵盤,如果我點擊 StrText,它會帶來相同的數(shù)字鍵盤而不是普通的文本鍵盤.如果你稍微玩一下,你會發(fā)現(xiàn)大部分時間都會返回數(shù)字鍵盤.請問我的代碼有問題嗎,或者我該如何解決?你會在下面找到我的代碼
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 構(gòu)建我的應(yīng)用程序時遇到了類似的問題.我在 android 中使用了默認的鍵盤應(yīng)用程序,但它仍然不斷地從 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 來構(gòu)建 .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.
注意:
我建議創(chuàng)建一個 virtualenv 來安裝上面的特定包并使用它來創(chuàng)建 .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
執(zhí)行 buildozer init
后,確保更改 buildozer.spec
文件:
After executing buildozer init
make sure to change buildozer.spec
file:
來自
requirements = kivy
到
requirements = kivy==1.9.1
否則它將使用最新的 kivy 版本來構(gòu)建 .apk 文件.
otherwise it will use the latest kivy version to build the .apk file.
更多關(guān)于 buildozer 的細節(jié)
希望對他人有所幫助!
這篇關(guān)于使用 kivy textinput 的 'input_type' 屬性的問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!