如何更改 gtk.MenuItem() 的背景颜色
对于用 Gtk 制作的弹出菜单,我希望将第一个菜单项作为标题。最好它的背景应该是白色的。因为——根据文档——无法更改gtk.Label
的背景颜色,而是必须更改其容器的背景,在我看来, gtk.MenuItem
本身应该被修改。
但是,我徒劳地尝试了以下操作:
menu_item.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#FFFFFF'))
这对于 gtk.EventBox 等容器有效,但对于 gtk.MenuItem 则无效。上面什么不起作用,我该怎么做才能让这个 gtk.MenuItem 背景变成白色?
PS:我不想为此使用任何 .rc 文件。
For a pop-up menu made in Gtk, I would like to have the first menu item as a header. Preferably its background should be white. Since---according to the documentation---one cannot change a gtk.Label
's background colour, but rather must change its container's background, it seemed to me the gtk.MenuItem
itself should be modified.
However, I have tried the following in vain:
menu_item.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#FFFFFF'))
This would work for a container as gtk.EventBox
, but for gtk.MenuItem
it does not. What's not working here above and what can I do to have this gtk.MenuItem
background white?
PS: i'd rather not use any .rc file for this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个示例,当鼠标悬停在“退出”菜单上时,该菜单将显示为白色。希望它可以帮助你!
为了做到这一点,我玩弄“风格”。
Here is a sample that puts the "exit" menu in white when mouse hovvers over it. Hope it can help you !
To do this, I play with the "style".
经过一番研究后,我发现这可以更改主菜单上的文本:
但是如果您希望菜单的整个背景为白色,则需要更改父菜单,而不是 MenuItem,如下所示:
After messing around with it, I found this will work to change the text on the main menu:
But if you want the whole background of the menu white, you need to change the parent menu, not the MenuItem, like this: