[英]Kivy right click menu
我試圖找到一種在Kivy中啟用常規右鍵單擊的方法,但是沒有任何運氣。
我可以找到一種方法來禁用多點觸控功能:
Config.set('input', 'mouse', 'mouse,disable_multitouch')
但是,右鍵單擊就像左鍵單擊一樣工作,我需要能夠復制,剪切,粘貼等。
我正在制作一個信息中心GUI。
您可以結合使用on_touch_down
和if touch.button == 'right':
來檢測右鍵單擊。
TextInput具有_show_copy_paste方法,該方法打開一個Bubble作為上下文菜單。
我認為使用Label不可能做到這一點。 如果您想實施它。 我建議您在啟用這些屬性的情況下制作自己的標簽,並從TextInput中汲取靈感。
這是很多工作。 因此,我更喜歡將TextInput與屬性readonly=True
。 我已經編碼了TextInput的版本,當右鍵單擊時會打開Contextmenu aka Bubbles。 這在下面的示例應用程序中實現。 我在Windows上進行了編碼和測試。
from kivy.app import App
from kivy.lang import Builder
from kivy.config import Config
from kivy.base import EventLoop
from kivy.uix.textinput import TextInput
Config.set('input', 'mouse', 'mouse,disable_multitouch')
class RightClickTextInput(TextInput):
def on_touch_down(self, touch):
super(RightClickTextInput,self).on_touch_down(touch)
if touch.button == 'right':
print("right mouse clicked")
pos = super(RightClickTextInput,self).to_local(*self._long_touch_pos, relative=True)
self._show_cut_copy_paste(
pos, EventLoop.window, mode='paste')
kv_string = Builder.load_string("""
RightClickTextInput:
use_bubble: True
text: ('Palimm'*10+"\\n")*40
multiline: True
#readonly: True
""")
class MyApp(App):
def build(self):
return kv_string
if __name__ == '__main__':
MyApp().run()
Kivy考慮到了移動設備。 如果您不進行任何觸摸操作,可能值得檢查一下tkinter。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.