pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <legend id='h27FX'><style id='h27FX'><dir id='h27FX'><q id='h27FX'></q></dir></style></legend>

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

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

        <bdo id='h27FX'></bdo><ul id='h27FX'></ul>
      <tfoot id='h27FX'></tfoot>
      1. 在 Kivy 中使用和移動小部件/按鈕

        Using and moving Widgets/Buttons in Kivy(在 Kivy 中使用和移動小部件/按鈕)

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

          • <tfoot id='13Vnp'></tfoot>
                <bdo id='13Vnp'></bdo><ul id='13Vnp'></ul>
                <legend id='13Vnp'><style id='13Vnp'><dir id='13Vnp'><q id='13Vnp'></q></dir></style></legend>
                  本文介紹了在 Kivy 中使用和移動小部件/按鈕的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我剛開始使用 Kivy,它與我習慣的不同,如果我犯了愚蠢的錯誤,請道歉!

                  I'm just starting off with Kivy and it's different to what I'm used to, apologies if I'm making stupid mistakes!

                  現在我正在嘗試創建一個執行以下操作的應用:

                  Right now I'm trying to create an app that does the following:

                  • 允許創建節點(現在是省略號).
                  • 允許用戶通過拖動來定位節點.
                  • 允許用戶用線連接節點.

                  到目前為止,我已經實現了第一個,并且在某種程度上實現了第二個.

                  So far I've achieved the first, and the second somewhat.

                  現在我的拖動效果不太好.如果我移動鼠標太快,它會取消移動方法(因為它不再接觸).有沒有更好的方法來產生拖動或者我只是增加刷新率(如果有的話怎么辦?).

                  Right now my dragging is not working too well. If I move the mouse too quickly it cancels the move method (as it is no longer in contact). Is there a better way to produce dragging or do I just increase the refresh rate (if so how?).

                  def on_touch_move(self, touch):
                     if self.collide_point(touch.x, touch.y):
                         self.pos=[touch.x-25, touch.y-25]
                  

                  我嘗試使用 Buttons,使用 on_press 方法更好地跟蹤移動.但是現在我很難更新按鈕的位置(主要是語法).

                  I've tried using Buttons instead, using the on_press method to track the moving better. However now I'm having difficulty updating the position of the button (mostly just syntax).

                      class GraphNode(Button):
                         background_disabled_down=1
                         background_disabled_normal=1
                  
                         def moveNode(self):
                             with touch:
                                 self.pos=[touch.x-25, touch.y-25]
                  

                  我不知道如何使用觸摸值,并不斷收到一系列錯誤.(顯然目前的嘗試是行不通的,我只是覺得很好笑).

                  I have no idea how to use the touch value, and keep getting an array of errors. (Obviously the current attempt doesn't work, I just thought it was funny).

                  您可能會說,我也不知道如何擺脫按鈕圖形,因為我想使用橢圓.如果有人可以告訴我如何在按下按鈕時更改橢圓的顏色,那將是一個額外的獎勵!

                  As you could probably tell, I also don't know how to get rid of the button graphics, as I want to use the ellipse. As an added bonus if someone could show me how to change the colour of the ellipse on button press that would be cool!

                  kv 文件:

                      <GraphNode>:
                          size: 50, 50
                          canvas:
                              Ellipse:
                                  pos: self.pos
                                 size: self.size
                          on_press:
                              root.moveNode()
                  

                  我希望能夠使用觸摸信息來更新位置,但這里不知道如何實現.

                  I want to be able to use the touch information to update the position, but don't know how to implement it here.

                  完整的核心python代碼:

                  Full core python code:

                      from kivy.app import App
                      from kivy.uix.widget import Widget
                      from kivy.uix.button import Button
                      from kivy.properties import NumericProperty, ReferenceListProperty,
                          ObjectProperty
                      from kivy.graphics import Color, Ellipse, Line
                  
                  
                      class GraphInterface(Widget):
                          node = ObjectProperty(None)
                  
                  
                  
                      class GraphApp(App):
                  
                          def build(self):
                              node = GraphNode()
                              game = GraphInterface()
                  
                              createNodeButton = Button(text = 'CreateNode', pos=(100,0))
                              createEdgeButton = Button(text = 'CreateEdge')
                              game.add_widget(createNodeButton)
                              game.add_widget(createEdgeButton)
                  
                              def createNode(instance):
                                  game.add_widget(GraphNode())
                                  print "Node Created"
                  
                              def createEdge(instance):
                                  game.add_widget(GraphEdge())
                                  print "Edge Created"
                  
                              createNodeButton.bind(on_press=createNode)
                              createEdgeButton.bind(on_press=createEdge)
                              return game
                  
                      class GraphNode(Button):
                  
                          def moveNode(self):
                              with touch:
                                  self.pos=[touch.x-25, touch.y-25]
                  
                  
                         #def onTouchMove(self, touch):
                         #   if self.collide_point(touch.x, touch.y):
                         #       self.pos=[touch.x-25, touch.y-25]
                          pass
                  
                      class GraphEdge(Widget):
                  
                          def __init__(self, **kwargs):
                              super(GraphEdge, self).__init__(**kwargs)
                              with self.canvas:
                                  Line(points=[100, 100, 200, 100, 100, 200], width=1)
                          pass
                  
                      if __name__ == '__main__':
                  
                          GraphApp().run()
                  

                  如果您需要任何其他信息,或者有任何不清楚的地方,請告訴我!

                  If you need any other info, or anything is unclear, please let me know!

                  第二個問題移至:在 Kivy 中創建動態繪制的線.

                  推薦答案

                  首先,你應該閱讀 觸摸事件.這里特別感興趣的是關于抓取觸摸事件的部分.基本上,您可以抓取"一個觸摸以確保抓取小部件將始終從該觸摸接收更多事件 - 換句話說,該觸摸事件之后的 on_touch_moveon_touch_up將發送到您的小部件.

                  First, you should read up on touch events in Kivy. Of particular interest here is the section on grabbing touch events. Basically, you can "grab" a touch to ensure that the grabbing widget will always receive further events from that touch - in other words, the on_touch_move and on_touch_up following that touch event will be sent to your widget.

                  基本示例:

                  class MyWidget(Widget):
                      def on_touch_down(self, touch):
                          if self.collide_point(*touch.pos):
                              touch.grab(self)
                              # do whatever else here
                  
                      def on_touch_move(self, touch):
                          if touch.grab_current is self:
                              # now we only handle moves which we have grabbed
                  
                      def on_touch_up(self, touch):
                          if touch.grab_current is self:
                              touch.ungrab(self)
                              # and finish up here
                  

                  但是,更好!如果您希望能夠拖動小部件,Kivy 已經有了:分散.

                  But, even better! If you want to be able to drag widgets around, Kivy already has that: Scatter.

                  只需將您的小部件包裝在 Scatter 中,您就可以拖動它.您還可以使用多點觸控來旋轉和縮放 Scatter,但您可以輕松禁用它 (kv):

                  Just wrap your widget in a Scatter and you can drag it around. You can also use multitouch to rotate and scale a Scatter, but you can easily disable that (kv):

                  FloatLayout:
                      Scatter:
                          do_scale: False
                          do_rotation: False
                  
                          MyWidget:
                  


                  旁注 - 這是不正確的:


                  Side note - this is incorrect:

                  class GraphNode(Button):
                     background_disabled_down=1
                     background_disabled_normal=1
                  

                  background_disabled_downbackground_disabled_normal 是 Kivy 屬性 - 你應該在 __init__ 中設置這些值.

                  background_disabled_down and background_disabled_normal are Kivy properties - you should set those values in __init__.

                  強制這些值:

                  class GraphNode(Button):
                      def __init__(self, **kwargs):
                          super(GraphNode, self).__init__(background_disabled_down='',
                                                          background_disabled_normal='', **kwargs)
                  

                  建議這些值(更好的選擇):

                  Suggest these values (better option):

                  class GraphNode(Button):
                      def __init__(self, **kwargs):
                          kwargs.setdefault('background_disabled_down', '')
                          kwargs.setdefault('background_disabled_normal', '')
                          super(GraphNode, self).__init__(**kwargs)
                  

                  最后,請注意這些屬性是 文件名指向用于禁用 Button 的圖像.如果您刪除這些值并禁用您的按鈕,它將不會繪制任何背景.

                  Finally, note that these properties are filenames pointing to the images used for the disabled Button. If you remove these values, and disable your button, it will draw no background whatsoever.

                  這篇關于在 Kivy 中使用和移動小部件/按鈕的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機器人?)
                  Discord bot isn#39;t responding to commands(Discord 機器人沒有響應命令)
                  Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關于我嗎?Discord 機器人的功能?(不和諧.py))
                  message.channel.id Discord PY(message.channel.id Discord PY)
                  How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機器人?)
                  discord.py - Automaticaly Change an Role Color(discord.py - 自動更改角色顏色)
                • <legend id='gqMyi'><style id='gqMyi'><dir id='gqMyi'><q id='gqMyi'></q></dir></style></legend>
                • <small id='gqMyi'></small><noframes id='gqMyi'>

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

                    <i id='gqMyi'><tr id='gqMyi'><dt id='gqMyi'><q id='gqMyi'><span id='gqMyi'><b id='gqMyi'><form id='gqMyi'><ins id='gqMyi'></ins><ul id='gqMyi'></ul><sub id='gqMyi'></sub></form><legend id='gqMyi'></legend><bdo id='gqMyi'><pre id='gqMyi'><center id='gqMyi'></center></pre></bdo></b><th id='gqMyi'></th></span></q></dt></tr></i><div class="dprbdjp" id='gqMyi'><tfoot id='gqMyi'></tfoot><dl id='gqMyi'><fieldset id='gqMyi'></fieldset></dl></div>
                    • <tfoot id='gqMyi'></tfoot>
                            <tbody id='gqMyi'></tbody>
                            主站蜘蛛池模板: 北京律师咨询_知名专业北京律师事务所_免费法律咨询 | 杭州公司变更法人-代理记账收费价格-公司注销代办_杭州福道财务管理咨询有限公司 | 机床主轴维修|刀塔维修|C轴维修-常州翔高精密机械有限公司 | 爱佩恒温恒湿测试箱|高低温实验箱|高低温冲击试验箱|冷热冲击试验箱-您身边的模拟环境试验设备技术专家-合作热线:400-6727-800-广东爱佩试验设备有限公司 | 智慧农业|农业物联网|现代农业物联网-托普云农物联网官方网站 | 三效蒸发器_多效蒸发器价格_四效三效蒸发器厂家-青岛康景辉 | 厂房出租_厂房出售_产业园区招商_工业地产&nbsp;-&nbsp;中工招商网 | 高低温老化试验机-步入式/低温恒温恒湿试验机-百科 | 次氯酸钠厂家,涉水级次氯酸钠,三氯化铁生产厂家-淄博吉灿化工 | 变频器维修公司_plc维修_伺服驱动器维修_工控机维修 - 夫唯科技 变位机,焊接变位机,焊接变位器,小型变位机,小型焊接变位机-济南上弘机电设备有限公司 | 西门子伺服控制器维修-伺服驱动放大器-828D数控机床维修-上海涌迪 | 圆窗水平仪|伊莉莎冈特elesa+ganter | 便民信息网_家电维修,家电清洗,开锁换锁,本地家政公司 | 学叉车培训|叉车证报名|叉车查询|叉车证怎么考-工程机械培训网 | PCB厂|线路板厂|深圳线路板厂|软硬结合板厂|电路板生产厂家|线路板|深圳电路板厂家|铝基板厂家|深联电路-专业生产PCB研发制造 | 螺钉式热电偶_便携式温度传感器_压簧式热电偶|无锡联泰仪表有限公司|首页 | 物流公司电话|附近物流公司电话上门取货 | Dataforth隔离信号调理模块-信号放大模块-加速度振动传感器-北京康泰电子有限公司 | 武汉创亿电气设备有限公司_电力检测设备生产厂家 | 衬氟止回阀_衬氟闸阀_衬氟三通球阀_衬四氟阀门_衬氟阀门厂-浙江利尔多阀门有限公司 | 北京自然绿环境科技发展有限公司专业生产【洗车机_加油站洗车机-全自动洗车机】 | 测试治具|过炉治具|过锡炉治具|工装夹具|测试夹具|允睿自动化设备 | cnc精密加工_数控机械加工_非标平键定制生产厂家_扬州沃佳机械有限公司 | 超声波_清洗机_超声波清洗机专业生产厂家-深圳市好顺超声设备有限公司 | 运动木地板厂家,篮球场木地板品牌,体育场馆木地板安装 - 欧氏运动地板 | 千淘酒店差旅平台-中国第一家针对TMC行业的酒店资源供应平台 | 辽宁资质代办_辽宁建筑资质办理_辽宁建筑资质延期升级_辽宁中杭资质代办 | 沥青灌缝机_路面灌缝机_道路灌缝机_沥青灌缝机厂家_济宁萨奥机械有限公司 | 螺旋压榨机-刮泥机-潜水搅拌机-电动泥斗-潜水推流器-南京格林兰环保设备有限公司 | 钢格板|镀锌钢格板|热镀锌钢格板|格栅板|钢格板|钢格栅板|热浸锌钢格板|平台钢格板|镀锌钢格栅板|热镀锌钢格栅板|平台钢格栅板|不锈钢钢格栅板 - 专业钢格板厂家 | 哈尔滨发电机,黑龙江柴油发电机组-北方星光 | 测试治具|过炉治具|过锡炉治具|工装夹具|测试夹具|允睿自动化设备 | 山东商品混凝土搅拌楼-环保型搅拌站-拌合站-分体仓-搅拌机厂家-天宇 | 挤出熔体泵_高温熔体泵_熔体出料泵_郑州海科熔体泵有限公司 | 食品质构分析仪-氧化诱导分析仪-瞬态法导热系数仪|热冰百科 | 深圳激光打标机_激光打标机_激光焊接机_激光切割机_同体激光打标机-深圳市创想激光科技有限公司 深圳快餐店设计-餐饮设计公司-餐饮空间品牌全案设计-深圳市勤蜂装饰工程 | 北京西风东韵品牌与包装设计公司,创造视觉销售力! | 换网器_自动换网器_液压换网器--郑州海科熔体泵有限公司 | 煤矿支护网片_矿用勾花菱形网_缝管式_管缝式锚杆-邯郸市永年区志涛工矿配件有限公司 | 太平洋亲子网_健康育儿 品质生活 | 光纤测温-荧光光纤测温系统-福州华光天锐光电科技有限公司 |