I'm trying to make a key event in python. I think that with curses module i can do that but i don't know how to. Please help me.
How can i call a function with a press of a keyboard key. Like, if "space" key is pressed do something, if "c" key is pressed show image, if "s" key is pressed save image. My problem is only to make that key event. I'm using Linux o.s.
I tried to use urwid module and when i use this code:
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")
appeared this error:
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)
What am i doing wrong ? How can i make it work?
ps: I'm sorry for my ignorance but i'm very new in python.
Thank you for answer