<tfoot id='CXYtM'></tfoot>
      <bdo id='CXYtM'></bdo><ul id='CXYtM'></ul>

  • <legend id='CXYtM'><style id='CXYtM'><dir id='CXYtM'><q id='CXYtM'></q></dir></style></legend>
    1. <i id='CXYtM'><tr id='CXYtM'><dt id='CXYtM'><q id='CXYtM'><span id='CXYtM'><b id='CXYtM'><form id='CXYtM'><ins id='CXYtM'></ins><ul id='CXYtM'></ul><sub id='CXYtM'></sub></form><legend id='CXYtM'></legend><bdo id='CXYtM'><pre id='CXYtM'><center id='CXYtM'></center></pre></bdo></b><th id='CXYtM'></th></span></q></dt></tr></i><div id='CXYtM'><tfoot id='CXYtM'></tfoot><dl id='CXYtM'><fieldset id='CXYtM'></fieldset></dl></div>

      <small id='CXYtM'></small><noframes id='CXYtM'>

        在 kivy 中,如何控制 TextInput 使用的 VKeyboard 的高

        时间:2023-10-09
        <legend id='th3Ch'><style id='th3Ch'><dir id='th3Ch'><q id='th3Ch'></q></dir></style></legend>

            <bdo id='th3Ch'></bdo><ul id='th3Ch'></ul>
            1. <tfoot id='th3Ch'></tfoot>
                <tbody id='th3Ch'></tbody>
                  <i id='th3Ch'><tr id='th3Ch'><dt id='th3Ch'><q id='th3Ch'><span id='th3Ch'><b id='th3Ch'><form id='th3Ch'><ins id='th3Ch'></ins><ul id='th3Ch'></ul><sub id='th3Ch'></sub></form><legend id='th3Ch'></legend><bdo id='th3Ch'><pre id='th3Ch'><center id='th3Ch'></center></pre></bdo></b><th id='th3Ch'></th></span></q></dt></tr></i><div id='th3Ch'><tfoot id='th3Ch'></tfoot><dl id='th3Ch'><fieldset id='th3Ch'></fieldset></dl></div>
                1. <small id='th3Ch'></small><noframes id='th3Ch'>

                  本文介绍了在 kivy 中,如何控制 TextInput 使用的 VKeyboard 的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个屏幕我想问一个问题,所以在 kv 语言中,我有

                  I have a Screen where I want to ask a question, so in the kv language, I have

                  Screen:
                          name: 'keyb'
                          BoxLayout:
                              orientation: 'vertical'
                              Label:
                                  id: rnl
                                  size_hint_y: .1
                                  text: ''
                              TextInput:
                                  id: tinput
                                  hint_text: '.mid'
                                  size_hint: (.8, .1)
                                  pos_hint: {'x': .1}
                                  multiline: False
                                  on_focus: root.focusCallback(args[1])
                              Widget:
                                  size_hint_y: .7
                  

                  当我想问问题时,我选择屏幕并将焦点设置到 TextInput

                  When I want to ask the question, I select the screen and set the focus to the TextInput

                   self.tinput.text = ""
                   self.screens.current = 'keyb'
                   Clock.schedule_once(self.focusKbd, .1)
                  

                  然后通过此代码级联:

                  def focusKbd(self, x):
                      self.tinput.focus = True
                  def focusCallback(self, f):
                      if not f:
                          # Deal with input now
                          self.screens.current = 'seq'
                  

                  在这段代码的某个地方,我想

                  Somewhere in this code, I would like to

                  1. 选择 TextInput 将要弹出的 VKeyboard 布局(在我的代码的其他部分会有所不同)
                  2. 调整 VKeyboard 的高度.

                  我不明白文本输入中的 VKeyboard 来自哪里;有什么方法可以从 TextInput 中获取对它的引用吗?

                  I don't understand where the VKeyboard comes from in Text Input; is there some way I can get a reference to it from the TextInput?

                  这是对 https://stackoverflow 的重述.com/questions/36414654/how-can-i-change-the-size-of-kivys-vkeyboard 那里有提示,但还不足以让我继续前进!

                  This is a restatement of https://stackoverflow.com/questions/36414654/how-can-i-change-the-size-of-kivys-vkeyboard There is a hint there, but not enough to get me going!

                  ***********************************************

                  ********************* **************************

                  为了理解 Tshirtman 的回答,我把它放在我的主要小部件的顶部:

                  Trying to understand the answer from Tshirtman, I put this at the top of my main widget:

                  Window.set_vkeyboard_class(get_vkeyboard())
                  

                  然后添加

                  def get_vkeyboard():
                      print '>>>>>>>>>>>>>>>>>>>>>>>>>>in get_vkeyboard'
                      return VKeyboard
                  

                  我发现 get_vkeyboard() 被立即调用,早在我需要键盘之前.所以似乎我无法在 get_vkeyboard() 中动态控制 VKeyboard 的外观.如果我感到困惑(我无疑是!),请纠正我.

                  I found that get_vkeyboard() was called immediately, long before I needed a keyboard. So it seems that I'm not going to be able to control anything about the appearance of the VKeyboard dynamically in get_vkeyboard(). Please correct me if I'm confused (which I undoubtedly am!).

                  还有其他方法可以动态修改 VKeyboard 的外观吗?

                  Is there some other way to modify the appearance of the VKeyboard dynamically?

                  附:Focus Behavior 中似乎有提示:

                  P.S. There seems to be a hint in Focus Behavior:

                  input_type 是一个 OptionsProperty,默认为text".可以是其中之一文本"、号码"、网址"、邮件"、日期时间"、电话"或地址".

                  input_type is an OptionsProperty and defaults to ‘text’. Can be one of ‘text’, ‘number’, ‘url’, ‘mail’, ‘datetime’, ‘tel’ or ‘address’.

                  我在 .kv 中的 TextInput 中添加了input_type: 'number'",但没有任何影响.

                  I added "input_type: 'number'" to a TextInput in .kv, but it didn't have any affect.

                  推荐答案

                  你可以使用 Window.set_vkeyboard_class 设置键盘类,但是没有什么能阻止你注册任何返回键盘实例的函数,所以您可以使用上下文(您的应用程序的状态)来动态决定将使用哪个类.由于在这种情况下您要自己返回一个实例,因此您可以决定它的大小、位置和其他详细信息.我在一些应用程序中使用了这种技术,以便在实例上使用 Animation 以将其平滑地放置在屏幕的特定位置.

                  You can set keyboard class using Window.set_vkeyboard_class, but nothing prevents you from registering any function that returns a keyboard instance there, so you could use the context (your app's state) to decide which class will be used, dynamically. Since you are returning an instance yourself in this case, you can decide of its size, pos, and other details. I used this technique in a few app to use Animation on the instance to place it in a particular spot of the screen smoothly.

                  伪例子:

                  from kivy.core.window import Window
                  from kivy.uix.vkeyboard import VKeyboard
                  from kivy.animation import Animation
                  from kivy.uix.screenmanager import ScreenManager, Screen
                  
                  class KeyboardA(VKeyboard):
                      def place(self):
                          self.center_x = Window.center_x
                          self.top = 0
                          Animation(y=100, t='out_elastic', d=.4).start(self)
                  
                  class KeyboardB(VKeyboard):
                       def place(self):
                          self.opacity = 0
                          Animation(opacity=1).start(self)
                  
                  class MyApp(App):
                       def build(self):
                           sm = ScreenManger()
                           sm.add_widget(Screen(name='a'))
                           sm.add_widget(Screen(name='b'))
                           return sm
                  
                       def get_keyboard(self, **kwargs):
                           if self.root.current == 'a':
                               kb = KeyboardA(**kwargs)
                  
                           else:
                               kb = KeyboardB(**kwargs)
                  
                           kb.place()
                           return kb
                  
                  Window.set_vkeyboard_class(app.get_keyboard)
                  

                  未经测试,但你应该明白.

                  untested, but you should get the idea.

                  这篇关于在 kivy 中,如何控制 TextInput 使用的 VKeyboard 的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Kivy 中的 Time.sleep 下一篇:kivy通过python动态添加自定义小部件到布局

                  相关文章

                  最新文章

                    <bdo id='HWQGW'></bdo><ul id='HWQGW'></ul>

                  <small id='HWQGW'></small><noframes id='HWQGW'>

                      <tfoot id='HWQGW'></tfoot>
                      <i id='HWQGW'><tr id='HWQGW'><dt id='HWQGW'><q id='HWQGW'><span id='HWQGW'><b id='HWQGW'><form id='HWQGW'><ins id='HWQGW'></ins><ul id='HWQGW'></ul><sub id='HWQGW'></sub></form><legend id='HWQGW'></legend><bdo id='HWQGW'><pre id='HWQGW'><center id='HWQGW'></center></pre></bdo></b><th id='HWQGW'></th></span></q></dt></tr></i><div id='HWQGW'><tfoot id='HWQGW'></tfoot><dl id='HWQGW'><fieldset id='HWQGW'></fieldset></dl></div>

                    1. <legend id='HWQGW'><style id='HWQGW'><dir id='HWQGW'><q id='HWQGW'></q></dir></style></legend>