我可以将徽标直接放在Gtk标题栏上吗? (没有小部件)

时间:2019-06-19 14:54:58

标签: python-3.x gtk3 graphical-logo

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

MainWindow(Gtk.Window)类:     “”“包含笔记本的主窗口”“”     def init (自己):         Gtk.Window。 init (self,title =“”)#由于标题为空白,默认标题栏带有Python图标         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直接在代码中设计徽标吗?

2 个答案:

答案 0 :(得分:0)

我明白了!我们无法将徽标直接放置在GTK 3中的任何小部件上。只能将图像小部件添加到标题栏顶部。

   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)

答案 1 :(得分:0)

enter image description here来自https://www.amazon.com/NuWallpaper-NU2235-Florentine-Stick-Wallpaper/dp/B06XT6S6PH的图像仅具有30%的透明度(使用gimp不透明度)

# 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()