[英]How to use python curses module to create a key event?
我正在嘗試在python中創建一個關鍵事件。 我認為使用curses模塊我可以做到,但我不知道如何。 請幫我。
如何通過按鍵盤鍵來調用功能。 就像,如果按下“空格”鍵做某事,如果按“c”鍵顯示圖像,如果按“s”鍵保存圖像。 我的問題只是制作那個關鍵事件。 我正在使用Linux操作系統
我嘗試使用urwid模塊,當我使用此代碼時:
import PIL
import Image
im=Image.open("im.tif")
imshow(im,cmap=cm.gray ,origin=1)
import urwid
def save(input):
if input in ('s'):
savefig("im2.png")
出現了這個錯誤:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 1413, in __call__
return self.func(*args)
File "/usr/lib/pymodules/python2.6/matplotlib/backends/backend_tkagg.py", line 312, in key_press
FigureCanvasBase.key_press_event(self, key, guiEvent=event)
File "/usr/lib/pymodules/python2.6/matplotlib/backend_bases.py", line 1143, in key_press_event
self.callbacks.process(s, event)
File "/usr/lib/pymodules/python2.6/matplotlib/cbook.py", line 163, in process
func(*args, **kwargs)
File "/usr/lib/pymodules/python2.6/matplotlib/backend_bases.py", line 1703, in key_press
self.canvas.toolbar.save_figure(self.canvas.toolbar)
TypeError: save_figure() takes exactly 1 argument (2 given)
我究竟做錯了什么 ? 我怎樣才能使它工作?
ps:我很抱歉我的無知,但我是蟒蛇新手。
謝謝你的答案
生成按鍵:
在Windows上,生成按鍵很容易。 在Linux上有點困難:
os.system('xvkbd -text "\\\\\\\\CP" ')
獲得關鍵新聞:
對於這種情況,使用curses有點多。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.