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

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

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

        <legend id='fQxRV'><style id='fQxRV'><dir id='fQxRV'><q id='fQxRV'></q></dir></style></legend>
        <tfoot id='fQxRV'></tfoot>

      1. 如何在 Kivy 文本输入中水平居中文本?

        时间:2023-10-09

            <bdo id='fHYBr'></bdo><ul id='fHYBr'></ul>
              <legend id='fHYBr'><style id='fHYBr'><dir id='fHYBr'><q id='fHYBr'></q></dir></style></legend>

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

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

                  <tfoot id='fHYBr'></tfoot>

                    <tbody id='fHYBr'></tbody>
                  本文介绍了如何在 Kivy 文本输入中水平居中文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想在 Kivy 文本输入中将单行文本居中.我将使用填充

                  I want to center a single line of text in Kivy text input. I'm going to use padding

                  widget.padding = [ (self.textinput.width - width of line) / 2, 20, 0, 0]
                  

                  但我找不到线的宽度.如何计算或访问线的宽度?

                  but i can't find the width of the line. How can I calculate or access the width of the line?

                  推荐答案

                  有一个内部 TextInput._get_text_width 方法可以用来计算正确的填充:

                  There is an internal TextInput._get_text_width method you can use to calculate proper padding:

                  from kivy.app import App
                  from kivy.uix.floatlayout import FloatLayout
                  from kivy.lang import Builder
                  
                  Builder.load_string('''
                  
                  <MyWidget>:
                      TextInput:
                          multiline: False
                          on_text: root.update_padding(args[0])
                          padding_x: self.width/2 # initial padding
                  ''')
                  
                  class MyWidget(FloatLayout):
                      def update_padding(self, text_input, *args):
                          text_width = text_input._get_text_width(
                              text_input.text,
                              text_input.tab_width,
                              text_input._label_cached
                          )
                          text_input.padding_x = (text_input.width - text_width)/2
                  
                  class MyApp(App):
                      def build(self):        
                          return MyWidget()
                  
                  if __name__ == '__main__':
                      MyApp().run()
                  

                  这篇关于如何在 Kivy 文本输入中水平居中文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 python 端动态调整 kivy 标签(和按钮)的大小 下一篇:Kivy 中的 Time.sleep

                  相关文章

                  最新文章

                  <legend id='UxL6h'><style id='UxL6h'><dir id='UxL6h'><q id='UxL6h'></q></dir></style></legend>

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

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