在 Windows 上的 GTK 中,如何更改整个应用程序的背景颜色?
根据 http://www.pygtk.org/docs/pygtk/gtk- Constants.html,有五种状态类型:STATE_NORMAL
、STATE_INSENSITIVE
等。我想设置Table、HBox、VBox等的背景颜色,并且我尝试设置每种状态的每种可能的颜色:
style = self.get_style()
for a in (style.base, style.fg, style.bg,
style.light, style.dark, style.mid,
style.text, style.base, style.text_aa):
for st in (gtk.STATE_NORMAL, gtk.STATE_INSENSITIVE,
gtk.STATE_PRELIGHT, gtk.STATE_SELECTED,
gtk.STATE_ACTIVE):
a[st] = gtk.gdk.Color(0, 34251, 0)
没有任何效果。 唯一有效果的是当我手动创建 EventBox 并专门使用现有的 gtk.STATE_NORMAL 颜色与其他颜色混合时。 不过,在没有我干预的情况下由 gtk 创建的所有内容都没有受到影响。
这样做的正确方法是什么? 我不介意必须制作一个 gtkrc 文件或其他文件。 这是因为 hbox、vbox 等没有颜色,但都是透明的吗? 那么谁提供应用程序的一般颜色呢?
According to http://www.pygtk.org/docs/pygtk/gtk-constants.html, there are five state types: STATE_NORMAL
, STATE_INSENSITIVE
, etc. I want to set the background color of a Table, HBox, VBox, whatever, and I've tried setting every possible color of every kind of state:
style = self.get_style()
for a in (style.base, style.fg, style.bg,
style.light, style.dark, style.mid,
style.text, style.base, style.text_aa):
for st in (gtk.STATE_NORMAL, gtk.STATE_INSENSITIVE,
gtk.STATE_PRELIGHT, gtk.STATE_SELECTED,
gtk.STATE_ACTIVE):
a[st] = gtk.gdk.Color(0, 34251, 0)
Nothing has any effect. The only one that has any effect is when I manually created EventBoxes and specifically used the existing gtk.STATE_NORMAL color to blend with other colors. All the ones created by gtk without my intervention were not affected, though.
What's the proper way to go about doing this? I wouldn't mind having to make a gtkrc file or whatever. Is this because hbox, vbox, etc., don't have a color, but are transparent? Who provides the general color of the application, then?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
主要是 google-fu(这里没有 Windows),作为“答案”发布主要是为了稍微更好的格式。 看看是否可以像 这里 那样尝试使用成熟的 gtkrc 带来了水果。 该位置基于此和这似乎有所不同 - 所以除非有人有找到它的确定性方法,否则 filemon 可能会一个明智的做法。
作为此类应用程序的主要用户,我更喜欢 gtkrc 中的设置,而不是程序员认为随时“最好”的硬编码设置。
Mostly google-fu (no windows here), posting as an "answer" mostly for a slightly better formatting. See if experimenting with the full-blown gtkrc like the one from here brings the fruits. The location, based on this and this appears to vary - so unless someone has the deterministic approach of finding it, filemon could be a sensible approach.
Being mostly a user for these kinds of apps, I would prefer the settings from my gtkrc over the hardcoded by what the programmer thought would be "the best", anytime.
这是因为VBox和Hbox没有关联的Window。
单击此处查看其他没有窗口的小部件。 我将创建事件框并在事件框中添加 HBox 或 VBox。
It's because VBox and Hbox don't have an associated Window.
click here to see other widgets without windows. I would create event boxes and add the HBox or VBox inside the event box.
更改样式后需要调用 self.set_style(style) 。 我使用您的代码作为模板,并添加该行使所有内容的背景都变成绿色。
You need to call
self.set_style(style)
after changing the style. I used your code as a template and adding that line makes the background of everything green.