库存图标未显示在按钮上
self.button = gtk.Button(stock=gtk.STOCK_DELETE)
只显示: 删除
self.button = gtk.Button(stock=gtk.STOCK_DELETE)
Only Shows:
Delete
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
无需更改任何系统配置文件即可设置属性的 Python 等效项是:
这应该在调用 window.show() 之后,并且显然在 gtk.main() 循环之前。
The Python equivalent for setting the property without having to change any system config files is:
This should follow a call to window.show() and, obviously, precede the gtk.main() loop.
这是 GTK 最近的一项更改 - 开发人员希望图标不要出现在按钮上。在 Linux 上,可以通过编辑
gconf
键来更改。在 Windows 上,我认为(我实际上没有尝试过这个)您需要在 gtkrc 文件中设置一个值(对我来说,它位于 < code>C:\Program Files\Gtk+\etc\gtkrc)并使用支持图标的主题(我认为默认主题不支持)。
您还可以在设置主题后将
gtk-button-images = 1
添加到您的~/.gtkrc-2.0
文件,这可能会覆盖主题来自gconf
的选项。编辑回答您的评论:
就像这个答案一样,但是用Python:在 Gtk 中,如何制作一个只有 Stock 图标的按钮?
对于 python,这只是
This is a recent change in GTK - the developers wanted icons not to appear on buttons. On Linux, this can be changed by editing the
gconf
keyOn windows, I think (I haven't actually tried this) that you need to set a value in your gtkrc file (for me it's in
C:\Program Files\Gtk+\etc\gtkrc
) and use a theme that supports icons (I think the default one doesn't).You can also add
gtk-button-images = 1
to your~/.gtkrc-2.0
file after setting the theme which may over ride the option fromgconf
.EDIT in answer to your comment:
Just like this answer, but in Python: In Gtk, how do I make a Button with just a stock icon?
For python, it's just
我必须这样做才能让它在 Python 中工作而不更改我的配置文件。当我调用 set_image() 时,没有显示图像。
I had to do this to get it to work from Python without changing my config file. When I called set_image(), no image was being displayed.
如果您使用 pygobject,新语法为:
If you work with pygobject, the new syntax is:
我在 Windows 上的 GTKmm 中遇到了同样的问题。 “MS-Windows”主题禁用库存按钮上的图像,并且该主题的优先级高于 gtkrc 中的设置(因此将 gtk-button-images = true 放入 gtkrc 中没有帮助)。我所做的是修改 GTK 设置运行时,图像按预期显示。 :) 这是 C++ 代码:
它应该放在第一个窗口构造之后。
I had the same issue in GTKmm on Windows. The "MS-Windows" theme disables images on stock buttons and the theme has priority over settings in gtkrc (so putting gtk-button-images = true in gtkrc didn't help). What I did is to modify the GTK settings runtime, and the images appeared as expected. :) Here's the code in C++:
It should be placed after the first window is constructed.
在 Gtk3 gtk.STOCK 方法中已 从 v3.10 开始已弃用。
在这种情况下,它没有帮助,因为它指向自定义标签解决方案(
new_with_label
)。如果您想使用 STOCK 内容,您仍然可以使用新方法Gtk.Button.new_from_icon_name( icon_name, size)
和Gtk.Button.new_with_mnemonic(label)
将分别创建带有常用图标和标签的新按钮。带有“stock”图标的新按钮示例:
带有“stock”标签的新按钮示例:
注意:在严肃的代码中创建常量变量而不是直接使用字符串是更好的选择:)
参考文献:
in Gtk3
gtk.STOCK
method has been deprecated from v3.10.In the case it doesn't help since it points to the custom label solution (
new_with_label
) If you want to use STOCK stuff you still can do so with new methodsGtk.Button.new_from_icon_name(icon_name, size)
andGtk.Button.new_with_mnemonic(label)
which will create new buttons with stock icon and label respectively.Example new button with a "stock" icon:
Example new button with a "stock" label:
NOTE: on serious code creating a constant variable instead of using the string straight is a better option :)
References:
您可以显式地显示按钮图像,只是,Gtk+ 开发人员不建议这样做,因为它会覆盖 Gtk+ 用户配置。
所以...
You can show explicitly the button image, justly, Gtk+ developers do not recommend doing this because it's overrides the Gtk+ user configuration.
So...