#!/usr/bin/env python3 import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, Gdk from .image import ScaleImage class ImageButton(Gtk.Button): def __init__(self, filepath, width = 26, height = 26): Gtk.Button.__init__(self) self.set_name('ImageButton') self.set_size_request(width, height) image = ScaleImage(filepath) image.resize(width, height) # 针对macos的设置, 但只解决了普通状态下的边框问题, 鼠标经过的样式还在 self.set_relief(Gtk.ReliefStyle.NONE) self.set_image(image) css_provider = Gtk.CssProvider() style = f""" #ImageButton, #ImageButton:hover {{ border: 0; background-color: transparent; border-color:transparent; outline: transparent; }} """ css_provider.load_from_data(style.encode('UTF-8')) context = self.get_style_context() path = context.get_path() context.add_provider(css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER)