简体   繁体   English

如何在python GTK3.0中将图标设置为模型按钮?

[英]How to set icon to model button in python GTK3.0?

I want to set icon to my model button in browser. 我想在浏览器中将图标设置为我的模型按钮。 I am using python GTK3.0 version with webkit2. 我在webkit2中使用python GTK3.0版本。 As of now here what I have did so far. 到目前为止,到目前为止,我所做的一切。

new_window_button = make_modelbutton(_("New Window"), 0.0, 0.5)
new_window_button.connect("clicked", lambda x: self.open_new_window())
new_window_label = make_modelbutton_label("[ Ctrl+N ]", 0.95, 0.5)

And the function for make_modelbutton() 以及make_modelbutton()的函数

def make_modelbutton(text, xalign, yalign):
    button = Gtk.ModelButton(label=text)
    button.set_alignment(xalign, yalign)
    button.get_child().set_padding(5, 5)

    return button

I tried to add set_image method but that didnot work. 我试图添加set_image方法,但是没有用。 I need help to set my icon. 我需要帮助来设置我的图标。 Thanks 谢谢

You should set the "icon" and "iconic" properties of the button with: 您应该使用以下命令设置按钮的“ icon”和“ iconic”属性:

button.props.icon (and set the Gio.Icon of your choice) plus set button.props.iconic to True, if the iconic property is not set or the icon is not valid it will display the text button.props.icon(并设置您选择的Gio.Icon)加上将button.props.iconic设置为True,如果未设置iconic属性或图标无效,它将显示文本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM