zoukankan      html  css  js  c++  java
  • kivy EventDispatcher

    Let's talk about kivy's EventDispatcher here:

    The codes I have tried here:

    codes here:

    from kivy.event import EventDispatcher
    class MyEventDispatcher(EventDispatcher):
        def __init__(self, **kwargs):
            self.register_event_type('on_test')
            super(MyEventDispatcher, self).__init__(**kwargs)
    
        def do_something(self, value):
            # when do_something is called, the 'on_test' event will be
            # dispatched with the value
            self.dispatch('on_test', value)
    
        def on_test(self, *args):
            print "I am dispatched", args

    Then I did this:

    def my_callback(value, *args):
        print "Hello, I got an event!", args
    
    
    ev = MyEventDispatcher()
    ev.bind(on_test=my_callback)
    ev.do_something('test')

    Python returned me with this:

    the method "my_callback" is bounded to "on_test" of the instance "ev"

    After binding, event triggers event

    从上面的输出看到,执行了ev.do_something 后

    Now if we don't bind the "my_callback", and just do 

    ev.do_something('test')

    let's see what we can get.

    由于没有用到dispatch 没有被先事先bind到,所以就比较难受地的给出了报错。ev.do_something   dispatch  不到 on_test 上面了。所以要事先声明一下就是bind一下。

  • 相关阅读:
    HDU 4685
    HDU 2519 新生晚会(组合问题)
    HDU 1241 Oil Deposits(递归,搜索)
    数据结构之线性表
    coocs项目的创建
    cocos开发环境搭建
    数据结构之算法时间复杂度
    c++ auto类型说明符
    HDU 6170 Two strings(DP)
    HDU 6138 Fleet of the Eternal Throne(AC自动机)
  • 原文地址:https://www.cnblogs.com/spaceship9/p/3455335.html
Copyright © 2011-2022 走看看