我工作的PyGTK的应用程序,可以生成图表。 这由matplotlib实现。 如何添加复制到剪贴板的功能? 如何复制图形到剪贴板?
Answer 1:
这将做它在Linux操作系统(只是在图像上单击鼠标,它被复制到剪贴板准备如GIMP中):
import matplotlib.pyplot as plt
from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas
import gtk
import numpy as np
class W(gtk.Window):
def __init__(self):
gtk.Window.__init__(self)
img = np.random.uniform(0,1,(200,200))
fig = plt.Figure()
fig.gca().imshow(img)
self.image_canvas = FigureCanvas(fig)
self.image_canvas.connect('button_press_event', self.do_clip)
self.add(self.image_canvas)
self.show_all()
def do_clip(self, widget=None, event=None):
snap = self.image_canvas.get_snapshot()
pixbuf = gtk.gdk.pixbuf_get_from_drawable(None, snap,
snap.get_colormap(),0,0,0,0,
snap.get_size()[0], snap.get_size()[1])
clip = gtk.Clipboard()
clip.set_image(pixbuf)
w=W()
gtk.main()
文章来源: PyGTK: copy matplotlib figure to clipboard