41 lines
774 B
Python
41 lines
774 B
Python
|
|
||
|
import gi
|
||
|
|
||
|
gi.require_version("Gtk", "3.0")
|
||
|
|
||
|
from gi.repository import Gtk, Gdk
|
||
|
from gi.repository.GdkPixbuf import Pixbuf
|
||
|
|
||
|
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
|
||
|
|
||
|
|
||
|
# 读剪切板中的文本
|
||
|
output = clipboard.wait_for_text()
|
||
|
|
||
|
# 写文本进剪切板
|
||
|
clipboard.set_text('blabla', -1)
|
||
|
|
||
|
|
||
|
|
||
|
# 从文件中读取
|
||
|
filepath = 'xxx.png'
|
||
|
image = Pixbuf.new_from_file(filepath)
|
||
|
|
||
|
# 从其他地方拿到的图片像素对象
|
||
|
image = Pixbuf.new_from_data(
|
||
|
data = bytes(image['bytes']),
|
||
|
colorspace = image['colorspace'],
|
||
|
has_alpha = image['has_alpha'],
|
||
|
bits_per_sample = image['bits_per_sample'],
|
||
|
width = image['width'],
|
||
|
height = image['height'],
|
||
|
rowstride = image['rowstride']
|
||
|
)
|
||
|
|
||
|
clipboard.set_image(image)
|
||
|
clipboard.store()
|
||
|
|
||
|
|
||
|
|
||
|
# 清除
|
||
|
clipboard.clear()
|