久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

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

      將函數綁定到kivy中的多個動態創建的按鈕?

      Bind a function to multiple dynamically created buttons in kivy?(將函數綁定到kivy中的多個動態創建的按鈕?)

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

          <tbody id='T3VTh'></tbody>

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

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

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

            <tfoot id='T3VTh'></tfoot>
              1. 本文介紹了將函數綁定到kivy中的多個動態創建的按鈕?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我想創建多個按鈕并將它們綁定到一個函數.問題是,每當我單擊一個按鈕時,都會多次調用該函數.似乎是事件連接的問題.當我查看按下按鈕時調用該函數的實例時,似乎該函數被一次從每個按鈕調用?!

                I want to create multiple buttons and bind them to a function. The problem is that whenever I click on one button, the function is called multiple times. It seems to be a problem with the event connection. When I look at the instance that called the function when I pressed a button, it seems that the function gets called from every button at once?!

                ...
                # This is the button that I'am using
                <ProjectSelectButton>:
                height: 35
                background_color: 0,0,1,1
                on_touch_down: self.click_on_button(args[0], args[1])
                
                ...
                
                # The buttons are added to this grid
                ButtonsPlacedHere@GridLayout:
                    id: active_projects
                    cols: 1
                    size_hint_y: None
                    height: self.minimum_height
                    spacing: 1
                ...
                

                Python 代碼:

                ...
                class ProjectSelectButton(Button):
                    def click_on_button(self, instance, touch, *args):
                        print(instance)
                        if touch.button == 'right':
                            print(self.id, "right mouse clicked")
                        else touch.buttom == 'left':
                            print(self.id, "left mouse clicked")
                
                ...
                
                # The part of my programm that creates the buttons
                # projects is a dictionary
                for key, project in data_manager.resource_pool.projects.items():
                    print(project.project_name)
                    button= ProjectSelectButton(text=project.project_name, id=key, size_hint_y=None)
                    # Bind without KV-File (same result)
                    # label.bind(on_touch_up=self.click_on_button)
                    ids.active_projects.add_widget(button)
                

                示例輸出:

                當我點擊一個按鈕時,我得到了什么!

                Example Output:

                What I get, when I click on a single button!

                <guiMain.ProjectSelectButton object at 0x0BA34260>
                ID01 right mouse clicked
                <guiMain.ProjectSelectButton object at 0x0BA34260>
                ID01 right mouse clicked
                <guiMain.ProjectSelectButton object at 0x0BA28F10>
                ID02 right mouse clicked
                <guiMain.ProjectSelectButton object at 0x0BA28F10>
                ID02 right mouse clicked
                <guiMain.ProjectSelectButton object at 0x0BA22C00>
                ID03 right mouse clicked
                <guiMain.ProjectSelectButton object at 0x0BA22C00>
                ID03 right mouse clicked
                

                當我按下 ID 為 01 的按鈕時我想要什么:

                What I want when I press for example the button with ID 01:

                <guiMain.ProjectSelectButton object at 0x0BA34260>
                ID01 right mouse clicked
                

                問題

                如何創建多個按鈕,當它們被按下時會調用一個函數?

                Question

                How do I create multiple buttons which will call a single function when they are pressed?

                推薦答案

                編程指南 ? 輸入管理 ? 觸摸事件

                默認情況下,觸摸事件會分派給所有當前顯示的小部件.這意味著無論是否發生在其物理區域內,小部件都會接收到觸摸事件.

                By default, touch events are dispatched to all currently displayed widgets. This means widgets receive the touch event whether it occurs within their physical area or not.

                為了提供最大的靈活性,Kivy 調度所有小部件的事件,并讓它們決定如何對它們做出反應.如果您只想響應小部件內的觸摸事件,您簡單檢查一下.

                In order to provide the maximum flexibility, Kivy dispatches the events to all the widgets and lets them decide how to react to them. If you only want to respond to touch events inside the widget, you simply check.

                解決方案

                click_on_button 方法中使用 self.collide_point 方法.當它碰撞時,你應該只得到一個按鈕.詳情請參考我的例子.

                Solution

                Use self.collide_point method in click_on_button method. When it collides, you should get only one button. Please refer to my example for details.

                class ProjectSelectButton(Button):
                    def click_on_button(self, instance, touch, *args):
                        print(instance)
                        if self.collide_point(*touch.pos):
                            if touch.button == 'right':
                                print(self.id, "right mouse clicked")
                            elif touch.buttom == 'left':
                                print(self.id, "left mouse clicked")
                            return True
                        return super(ProjectSelectButton, self).on_touch_down(touch)
                

                示例

                main.py

                from kivy.app import App
                from kivy.uix.gridlayout import GridLayout
                from kivy.uix.button import Button
                
                
                class CreateButton(Button):
                
                    def on_touch_down(self, touch):
                        if self.collide_point(*touch.pos):
                            if touch.button == "right":
                                print(self.id, "right mouse clicked")
                            elif touch.button == "left":
                                print(self.id, "left mouse clicked")
                            else:
                                print(self.id)
                            return True
                        return super(CreateButton, self).on_touch_down(touch)
                
                
                class OnTouchDownDemo(GridLayout):
                
                    def __init__(self, **kwargs):
                        super(OnTouchDownDemo, self).__init__(**kwargs)
                        self.build_board()
                
                    def build_board(self):
                        # make 9 buttons in a grid
                        for i in range(0, 9):
                            button = CreateButton(id=str(i))
                            self.add_widget(button)
                
                
                class OnTouchDownApp(App):
                
                    def build(self):
                        return OnTouchDownDemo()
                
                
                if __name__ == '__main__':
                    OnTouchDownApp().run()
                

                ontouchdown.kv

                #:kivy 1.10.0
                
                <CreateButton>:
                    font_size: 50
                    on_touch_down: self.on_touch_down
                
                <OnTouchDownDemo>:
                    rows: 3
                    cols: 3
                    row_force_default: True
                    row_default_height: 150
                    col_force_default: True
                    col_default_width: 150
                    padding: [10]
                    spacing: [10]
                

                這篇關于將函數綁定到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 - 自動更改角色顏色)

                    <tbody id='TUI2i'></tbody>

                    <tfoot id='TUI2i'></tfoot>

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

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

                          主站蜘蛛池模板: 欧美日韩一 | 久久蜜桃精品 | 青青久在线视频 | 亚洲第一色站 | 亚洲综合在线视频 | 久久av一区二区 | 国产激情亚洲 | 国产精品亚洲一区二区三区在线 | 一级午夜aaa免费看三区 | 在线观看中文视频 | 中文字幕 国产精品 | 一区二区三区欧美 | 成人一区二区三区 | 不卡视频在线 | 孕妇一级毛片 | 亚洲444kkkk在线观看最新 | 国产成人精品网站 | 国产精品久久国产精品 | heyzo在线 | 中文字幕一二三区 | www国产成人免费观看视频,深夜成人网 | 一区二区三区在线播放 | 看羞羞视频免费 | 中文字幕高清一区 | 国产yw851.c免费观看网站 | 韩日有码 | 国产精品色 | 精品视频 免费 | 日韩一区二区三区在线观看 | 久久久久久中文字幕 | 免费精品 | 欧美成人在线网站 | 欧美激情a∨在线视频播放 成人免费共享视频 | av性色| 精品国产精品三级精品av网址 | 欧美精品一区久久 | 免费a网站 | 熟女毛片 | 天天干天天插天天 | 精品欧美乱码久久久久久 | 久久久久久亚洲欧洲 |