【发布时间】:2018-08-16 22:22:37
【问题描述】:
我在 Kivy 中创建了一个自定义 Button 类,带有一些回调方法,当我右键单击按钮时,我希望能够从几个不同的操作中进行选择:
from kivy.config import Congfig
Config.set('input', 'mouse', 'mouse,multitouch_on_demand')
from kivy.app import App
from kivy.uix import Button
class CustomButton(Button):
"""This is just for demonstration"""
def __init__(self, name='', **kwargs):
super(Service, self).__init__(**kwargs)
self.name = name
self.on_touch_down = self.mouse_click
def mouse_click(self, touch):
if self.collide_point(touch.x, touch.y):
if touch.button == 'right':
# Open context menu
pass
def callback_1(self):
# This will be called from one of the context options
pass
def callback_2(self):
# Or this will be called from a different option
pass
代码仅用于演示目的,以表达我想要实现的目标。这可能吗?
提前致谢。
【问题讨论】:
标签: python user-interface button kivy contextmenu