zoukankan      html  css  js  c++  java
  • kivy Label触发事件

    kivy  label也可以触发事件,为什么只有我这么无聊学垃圾kivy

    """
    在通过ref标记一段文本后点击这段文本就可以触发'on_ref_press'事件,在该事件中调用相关的回调函数去处理业务逻辑即可
    一定记得markup=True
    """
    
    from kivy.app import App
    from kivy.uix.boxlayout import BoxLayout
    from kivy.uix.label import Label
    from kivy.lang import Builder
    import webbrowser
    
    
    Builder.load_string("""
    
    """)
    
    
    class LabelBoxLayout(BoxLayout):
        def __init__(self):
            super().__init__()
            label_ref=Label(
                # text="打开百度网页",
                text="open [color=#FF0000][ref=baidu]baidu[/ref][/color]",
                markup=True,
            )
            label_ref.bind(on_ref_press=self.open_baidu)  # 触发点击事件
            self.add_widget(label_ref)
    
        @staticmethod
        def open_baidu(*args):
            webbrowser.open('www.baidu.com')
    
    
    class LabelApp(App):
        def build(self):
            return LabelBoxLayout()
    
    
    if __name__ == '__main__':
        from kivy.core.window import Window
        Window.clearcolor=[1,1,1,1]    # 设置主窗口颜色
        LabelApp().run()
  • 相关阅读:
    java线程
    面向切面编程
    控制反转IOC与依赖注入DI
    phpexecel 导入导出,格式
    PHPExcel设置数据格式的几种方法
    九度oj 题目1416:猴子吃坚果
    九度oj 题目1397:查找数段
    poj 1065 Wooden Sticks
    poj 3181 Dollar Dayz
    poj 1742 Coins
  • 原文地址:https://www.cnblogs.com/vip136510786/p/15057422.html
Copyright © 2011-2022 走看看