This repository has been archived on 2023-09-06. You can view files and clone it, but cannot push or open issues/pull-requests.
yutent
/
py-gtk-notes
Archived
1
0
Fork 0
py-gtk-notes/notes/clipboard.py

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()
python + gtk3 + webkit2 学习笔记
Python 60.1%
JavaScript 37.6%
HTML 2.3%