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

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

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

        用kivy按下按钮时如何更改空格?

        时间:2023-06-06
          <tbody id='Jqe8v'></tbody>

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

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

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

                  本文介绍了用kivy按下按钮时如何更改空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试通过实现

                  问:如何配置 drawingspace.kv 以使每个按下的按钮具有不同的布局和不同的小部件?

                  解决方案

                  一个巧妙的方法是使用屏幕.

                  由于我已经从您之前的问题中获得了此应用程序的示例,因此很容易实现屏幕,并稍微重写类.

                  当按下按钮时,您将屏幕管理器的当前设置为您想要的屏幕名称.

                  然后您只需在每个屏幕、kv 文件或 python 文件中根据需要编辑布局.

                  我选择在这里用 kv 语言制作大部分布局内容.因为我发现以我想要的方式开发布局更容易.以后如果我愿意,我可以将它重写为 python.

                  所以我的 python 文件现在看起来像这样:

                  从 kivy.app 导入 App从 kivy.uix.boxlayout 导入 BoxLayout从 kivy.properties 导入 StringProperty从 kivy.clock 导入时钟从 kivy.uix.screenmanager 导入 Screen,ScreenManager,NoTransition从 kivy.lang 导入生成器进口时间builder.load_file("kv.kv")类 MyLayout(BoxLayout):def __init__(self,**kwargs):super(MyLayout,self).__init__(**kwargs)self.orientation = "垂直"self.padding = 10类 MainScreen(屏幕):经过类删除屏幕(屏幕):经过类 GroupScreen(屏幕):经过MyLogo 类(BoxLayout):your_time = StringProperty()def __init__(self,**kwargs):super(MyLogo,self).__init__(**kwargs)Clock.schedule_interval(self.set_time, 0.1)def set_time(self,dt):self.your_time = time.strftime("%m/%d/%Y %H:%M")我的应用程序(应用程序)类:def __init__(self,**kwargs):super(MyApp,self).__init__(**kwargs)self.sm = ScreenManager(transition=NoTransition())self.sm.add_widget(MainScreen(name = "main"))self.sm.add_widget(RemoveScreen(name = "remove"))self.sm.add_widget(GroupScreen(name = "group"))self.sm.current = "主要"定义构建(自我):返回自我.sm如果 __name__ == "__main__":MyApp().run()

                  而 kv.kv 文件看起来像这样:

                  #:kivy 1.9.1<MyButtons@BoxLayout>:填充:10,10,10,0间距:10大小提示:1,0.3方向:水平"按钮:文字:清除"on_press: app.sm.current = "main"按钮:文字:删除"on_press: app.sm.current = "删除"按钮:文字:组"on_press: app.sm.current = "组"按钮:文字:颜色"按钮:文字:手势"<我的标志>:间距:10填充:10,10,10,0方向:水平"盒子布局:方向:垂直"大小提示:0.3,1帆布:长方形:pos: self.pos尺寸:self.size异步图像来源:'http://lmsotfy.com/so.png'标签:大小提示:1,0.3文本:root.your_time颜色:[0,0,0,1]标签:大小提示:1,0.3文本:纽约市,纽约,美国"颜色:[0,0,0,1]<主屏幕>:我的布局:我的标志:#按钮:# 文本:主要"我的按钮:#纽扣盒子布局:填充:10,10,10,10大小提示:1,0.3按钮:文本:总数:1 Kivy Started"<删除屏幕>:我的布局:我的标志:盒子布局:方向:水平"标签:字体大小:40sp"文字:删除"按钮:字体大小:20sp"文字:删除这个或其他东西"我的按钮:#纽扣盒子布局:填充:10,10,10,10大小提示:1,0.3按钮:文本:总数:1 Kivy Started"<组画面>:我的布局:我的标志:盒子布局:方向:垂直"标签:字体大小:40sp"文字:组"按钮:字体大小:20sp"文本:某些东西分组"我的按钮:#纽扣盒子布局:填充:10,10,10,10大小提示:1,0.3按钮:文本:总数:1 Kivy Started"

                  I am trying create a GUI by implementing the template of the ComicCreator GUI sample as a template for my own project. The code is easy to follow, but I would like to be able to reconfigure the drawingspace.kv, each time a button is pushed, say for example something like this:

                  Q: How could I configure the drawingspace.kv to have a different layout with different widgets for each button that is pressed?

                  解决方案

                  A neat way to do this is to use screen.

                  Since I allready have an example of this app from you earlier question, it was easy to implement the screens, and rewrite the classes a bit.

                  When a button is pressed, you set the screenmanager's current to whatever the name you named the screen you want.

                  Then you just edit the layouts as you want inside of each screen, in the kv file, or python file.

                  I choose to make most of the layout stuff in kv language here. Because I find it easier to develop a layout the way I want it this way. Later I could rewrite it to python if I want that.

                  So my python file looks like this now:

                  from kivy.app import App
                  from kivy.uix.boxlayout import BoxLayout
                  from kivy.properties import StringProperty
                  from kivy.clock import Clock
                  from kivy.uix.screenmanager import Screen,ScreenManager,NoTransition
                  from kivy.lang import Builder
                  import time
                  
                  
                  Builder.load_file("kv.kv")
                  
                  
                  class MyLayout(BoxLayout):
                  
                      def __init__(self,**kwargs):
                          super(MyLayout,self).__init__(**kwargs)
                          self.orientation = "vertical"
                          self.padding = 10
                  
                  
                  class MainScreen(Screen):
                      pass
                  
                  
                  class RemoveScreen(Screen):
                      pass
                  
                  
                  class GroupScreen(Screen):
                      pass
                  
                  
                  class MyLogo(BoxLayout):
                  
                      your_time = StringProperty()
                      def __init__(self,**kwargs):
                          super(MyLogo,self).__init__(**kwargs)
                          Clock.schedule_interval(self.set_time, 0.1)
                  
                      def set_time(self,dt):
                          self.your_time = time.strftime("%m/%d/%Y %H:%M")
                  
                  
                  
                  
                  class MyApp(App):
                      def __init__(self,**kwargs):
                          super(MyApp,self).__init__(**kwargs)
                          self.sm = ScreenManager(transition=NoTransition())
                  
                          self.sm.add_widget(MainScreen(name = "main"))
                          self.sm.add_widget(RemoveScreen(name = "remove"))
                          self.sm.add_widget(GroupScreen(name = "group"))
                  
                          self.sm.current = "main"
                  
                      def build(self):
                          return self.sm
                  
                  
                  if __name__ == "__main__":
                      MyApp().run()
                  

                  And kv.kv file looks like this:

                  #:kivy 1.9.1
                  
                  <MyButtons@BoxLayout>:
                      padding: 10,10,10,0
                      spacing: 10
                      size_hint: 1,0.3
                      orientation: "horizontal"
                      Button:
                          text: "Clear"
                          on_press: app.sm.current = "main"
                      Button:
                          text: "Remove"
                          on_press: app.sm.current = "remove"
                      Button:
                          text: "Group"
                          on_press: app.sm.current = "group"
                      Button:
                          text: "Color"
                      Button:
                          text: "Gestures"
                  
                  <MyLogo>:
                      spacing: 10
                      padding: 10,10,10,0
                      orientation: "horizontal"
                      BoxLayout:
                          orientation: "vertical"
                          size_hint: 0.3,1
                          canvas:
                              Rectangle:
                                  pos: self.pos
                                  size: self.size
                          AsyncImage
                              source: 'http://lmsotfy.com/so.png'
                          Label:
                              size_hint: 1,0.3
                              text: root.your_time
                              color: [0,0,0,1]
                          Label:
                              size_hint: 1,0.3
                              text: "NYC, New York, USA"
                              color: [0,0,0,1]
                  
                  
                  <MainScreen>:
                      MyLayout:
                          MyLogo:
                              #Button:
                              #    text: "main"
                  
                          MyButtons:
                              #buttons
                  
                          BoxLayout:
                              padding: 10,10,10,10
                              size_hint: 1,0.3
                              Button:
                                  text: "Total figures: 1          Kivy Started"
                  
                  
                  <RemoveScreen>:
                      MyLayout:
                          MyLogo:
                              BoxLayout:
                                  orientation: "horizontal"
                                  Label:
                                      font_size: "40sp"
                                      text: "Remove"
                                  Button:
                                      font_size: "20sp"
                                      text: "Remove this or something"
                  
                          MyButtons:
                              #buttons
                  
                          BoxLayout:
                              padding: 10,10,10,10
                              size_hint: 1,0.3
                              Button:
                                  text: "Total figures: 1          Kivy Started"
                  
                  
                  <GroupScreen>:
                      MyLayout:
                          MyLogo:
                              BoxLayout:
                                  orientation: "vertical"
                                  Label:
                                      font_size: "40sp"
                                      text: "Group"
                                  Button:
                                      font_size: "20sp"
                                      text: "Something groups stuff"
                  
                          MyButtons:
                              #buttons
                  
                          BoxLayout:
                              padding: 10,10,10,10
                              size_hint: 1,0.3
                              Button:
                                  text: "Total figures: 1          Kivy Started"
                  

                  这篇关于用kivy按下按钮时如何更改空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在微调器中允许无限整数值? 下一篇:如何在 Kivy 中拥有多个窗口?

                  相关文章

                  <small id='2yGRR'></small><noframes id='2yGRR'>

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

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

                      <tfoot id='2yGRR'></tfoot>