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

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

      <tfoot id='usCqH'></tfoot>

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

        • <bdo id='usCqH'></bdo><ul id='usCqH'></ul>

        Kivy - 为 reStructuredText 创建样式按钮

        时间:2023-10-09
        <tfoot id='xpsZj'></tfoot>

            • <small id='xpsZj'></small><noframes id='xpsZj'>

                <tbody id='xpsZj'></tbody>
            • <legend id='xpsZj'><style id='xpsZj'><dir id='xpsZj'><q id='xpsZj'></q></dir></style></legend>
                <bdo id='xpsZj'></bdo><ul id='xpsZj'></ul>
                <i id='xpsZj'><tr id='xpsZj'><dt id='xpsZj'><q id='xpsZj'><span id='xpsZj'><b id='xpsZj'><form id='xpsZj'><ins id='xpsZj'></ins><ul id='xpsZj'></ul><sub id='xpsZj'></sub></form><legend id='xpsZj'></legend><bdo id='xpsZj'><pre id='xpsZj'><center id='xpsZj'></center></pre></bdo></b><th id='xpsZj'></th></span></q></dt></tr></i><div id='xpsZj'><tfoot id='xpsZj'></tfoot><dl id='xpsZj'><fieldset id='xpsZj'></fieldset></dl></div>
                  本文介绍了Kivy - 为 reStructuredText 创建样式按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想在 Kivy 中为 reStructuredText 小部件创建按钮.这些按钮可以做一些基本的事情,比如粗体、下划线或制作标题,这样用户就不必手动输入标记.例如,用户可以选择一些文本然后单击粗体"按钮,然后文本将被 [b]...[/b] 包围.

                  I would like to create buttons for the reStructuredText widget in Kivy. The buttons would do basic things like bold, underline, or make a heading so the user doesn't have to manually type in the markup. For example, the user could select some text then click the 'bold' button and the text would then be surrounded by [b]...[/b].

                  我很想展示我尝试过的代码,但老实说,我什至不知道从哪里开始.(或者请让我知道是否有更好的方法可以在 Kivy 中实现基本文本编辑.)我目前正在使用 Kivy 语言通过简单地添加来显示第一个小部件

                  I would love to show code of what I've tried but I honestly don't even know where to begin. (Or please let me know if there is a better way to implement basic text editing in Kivy.) I'm currently using the Kivy language to display the rst widget by simply adding

                  RstDocument:
                      show_errors: True
                  

                  到 kv 文件(连同保存等按钮).

                  to the kv file (along with the save, etc... buttons).

                  推荐答案

                  在您的问题中,我第一次听说 RstDocument 小部件.你让我感兴趣,我想出了一个最小的示例应用程序,这可能是你添加更多内容的一个很好的起点.这是我的python文件

                  In your question, I heard about the RstDocument widget for the first time. You got me interested and I came up with a minimal sample app which could be a good starting point for you to add more. This is my python file

                  from kivy.app import App
                  from kivy.base import Builder
                  from kivy.uix.button import Button
                  from kivy.uix.boxlayout import BoxLayout
                  
                  
                  
                  Builder.load_string("""
                  <root_wgt>:
                      orientation: 'vertical'
                      BoxLayout:
                          size_hint_y:0.2
                          Button:
                              text: 'Emphasize'
                              on_press: root.emphasize()
                          Button:
                              text: 'Section Header'
                              on_press: root.add_section_header()
                          Button:
                              text: 'Subection Header'
                              on_press: root.add_sub_section_header()
                  
                      BoxLayout:
                          orientation: 'vertical'
                          TextInput:
                              id: textinput
                  
                          RstDocument:
                              id: rstdocument
                              text: textinput.text
                  """)
                  
                  
                  class root_wgt(BoxLayout):
                      def emphasize(self):
                          text = self.ids.textinput.text
                          selection = self.ids.textinput.selection_text
                          begin = self.ids.textinput.selection_from
                          end = self.ids.textinput.selection_to
                          new_text = text[:begin] + ' **' + selection + '** ' + text[end:]
                          self.ids.textinput.text = new_text
                          self.ids.rstdocument.render()
                  
                      def add_section_header(self):
                          self.ids.textinput.insert_text("""
                  ==============""")
                  
                      def add_sub_section_header(self):
                          self.ids.textinput.insert_text("""
                  -----------------""")
                  
                  class MyApp(App):
                      def build(self):
                          return root_wgt()
                  
                  if __name__ == '__main__':
                      MyApp().run()
                  

                  或者,您可以只使用一个标签,该标签也有一些样式选项 https://kivy.org/docs/api-kivy.uix.label.html#markup-text 实现看起来非常相似.

                  Alternatively, you could just go with a label which also has some styling options https://kivy.org/docs/api-kivy.uix.label.html#markup-text The implementation would look quite similar.

                  这篇关于Kivy - 为 reStructuredText 创建样式按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:un_active 按钮,直到函数在 kivy 中完成 下一篇:在 python 中为移动应用程序创建主菜单

                  相关文章

                  最新文章

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

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

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

                      • <bdo id='Umubp'></bdo><ul id='Umubp'></ul>