可以直接把Logo放在Gtkheader栏吗? (没有小部件)

Can I put Logo directly on Gtk header bar? (without widget)

我正在尝试将徽标直接放在 Gtk.Headerbar 上以代替标题。徽标是在 Microsoft Word 中创建的。 下面是我的部分代码

class 主窗口(Gtk.Window): """Main window containing notebook""" def init(self): Gtk.Window.init(self, title="") # 由于标题为空,默认header bar with Python icon self.set_border_width(10) 屏幕 = self.get_screen() screen_width = screen.get_width() screen_height = screen.height()

    if screen_width > 1366 or screen_height > 768:
        self.set_size_request(1300, 800)

    else:
        self.set_size_request(screen_width, screen_height)

    self.set_resizable(True)

    self.set_resizable(True)

    # self.maximize()
    # Creating headerbar & adding it to our window
    title = "Pareto"
    subtitle = "Shape your world"
    header_bar = Gtk.HeaderBar(title=title, subtitle=subtitle)
    header_bar.set_show_close_button(True)


    samco_logo = Gtk.Image.new_from_file(r"C:\Users\njoshi\Desktop\pareto\icons\pareto_logo1.png")
    # this line convert the created icon to an image

    header_bar.pack_start(samco_logo)
    time_label = TimeLabel()             # show time on header bar
    header_bar.pack_end(time_label)
    self.set_titlebar(header_bar)

    # creating a notebook
    notebook = Gtk.Notebook()

现在我正在使用 Gtk.Image 徽标小部件。我可以使用 html 直接在我的代码中设计徽标吗?

我明白了!在 GTK 3 中,我们无法将徽标直接放在任何小部件上。唯一的方法是在 header 栏顶部添加图像小部件。

   self.header_bar = Gtk.HeaderBar()
    self.header_bar.props.title = "Pareto"

    self.header_bar.set_show_close_button(True)
    pareto_logo =  Gtk.Image.new_from_file(r"loc\image.png")
    self.header_bar.pack_start(pareto_logo)

Image is only 30% transparent (using gimp opacity) from https://www.amazon.com/NuWallpaper-NU2235-Florentine-Stick-Wallpaper/dp/B06XT6S6PH

# set Background Image using CSS
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk, Gio
from random import randint

class MyCSSThemedWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="Background Image Demo")
        self.hb = Gtk.HeaderBar()
        self.hb.set_show_close_button(True)
        self.hb.props.title = "Background Image on Button, Headerbar and Window"
        self.set_titlebar(self.hb)

        self.hb_menu_button = Gtk.Button()
        icon = Gio.ThemedIcon(name="open-menu-symbolic")
        image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON)
        self.hb_menu_button.add(image)
        self.hb_menu_button.set_name("styled_button") #for button on headerbar
        self.hb.pack_end(self.hb_menu_button)
        
        #self.hb.set_show_close_button(False)
        #self.hb_menu_button.set_relief(Gtk.ReliefStyle.NONE)

        self.set_border_width(15)
        self.set_default_size(800, 500)

        self.hbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
        self.add(self.hbox)
    
      
        screen = Gdk.Screen.get_default()
        provider = Gtk.CssProvider()
        style_context = Gtk.StyleContext()
        style_context.add_provider_for_screen(screen, provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

        # see https://developer.gnome.org/gtk3/stable/chap-css-overview.html for gradient etc effects
        css = b"""
        #styled_button {
            
            background-image: url('./nuwallpaper.jpg');
        }
        radiobutton:checked {
            background-color: #56f9a0;
        }
        headerbar {
        background-image: url('./nuwallpaper.jpg');
        background-position: left top;
        }
        window.background {
            background-image: url('./nuwallpaper.jpg');
        background-size: contain;
        background-position: left top;
        border: 0px solid black;
        }
        
        """
        
        provider.load_from_data(css)
        




# Main Program
win = MyCSSThemedWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()