Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
627 views
in Technique[技术] by (71.8m points)

python - How do I get the kivy Window.softinput_mode = 'below_target' to move the TextInput box above the virtual keyboard?

I'm using python 3.8.6 and kivy 2.1.0.

When the text input box gets focus, the keyboard pops up and covers the TextInput box. I've added the 2 lines below to force the keyboard to be below the target TextInput box, but it does not work as expected.

Window.keyboard_anim_args = {"d":.2,"t":"linear"}
Window.softinput_mode = "below_target"

I've also tried 'pan' and 'resize'. The code runs with no errors, but none of these settings has any effect on the behavior, so I'm sure I'm missing something obvious, but it's not obvious to me:-(. Any help is greatly appreciated. The full code follows:

from kivy.app import App
from kivy.core.window import Window
from kivy.uix.button import  Button
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
from kivy.config import Config

Window.keyboard_anim_args = {"d":.2,"t":"linear"}
Window.softinput_mode = "below_target"
#Window.softinput_mode = 'pan'
#Window.softinput_mode = 'resize'

class ClearApp(App):
    def build(self):
        self.box = BoxLayout(orientation='horizontal', spacing=10)
        self.txt = TextInput(hint_text='Write here', 
                             keyboard_mode='auto', 
                             size_hint=(.5,.1))
        self.btn = Button(text='Clear All', 
                          on_press=self.clearText, size_hint=(.1,.1))
        self.box.add_widget(self.txt)
        self.box.add_widget(self.btn)
        return self.box
    def clearText(self, instance):
        self.txt.text = ''
'''
if Config:
    _is_desktop = Config.getboolean('kivy', 'desktop')
    _keyboard_mode = Config.get('kivy', 'keyboard_mode')
    if _is_desktop:
        Config.set('kivy', 'keyboard_mode','system')
        Config.write()
    else:
        Config.set('kivy', 'keyboard_mode','systemanddock')
        Config.write()    
'''        
Config.set('kivy', 'keyboard_mode','dock')
Config.write()        

ClearApp().run()
question from:https://stackoverflow.com/questions/65847019/how-do-i-get-the-kivy-window-softinput-mode-below-target-to-move-the-textinp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...