我已经尝试过更改Filechooser Button的背景颜色,但没有改变..
gtkrc文件:
style "FilechooserButtonStyle" = "button_style"
{
base[NORMAL] = '#F5F5F5'
base[SELECTED] = 'red'
bg[NORMAL] = 'green'
bg_pixmap[NORMAL] = "button.jpg"
xthickness = 10
ythickness = 10
GtkFileChooserButton::set_app_paintable = True
}
在py文件中:
file_chooser.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse("red"))
file_chooser.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color('gray'))
我怎么能解决这个问题?
提前致谢!
答案 0 :(得分:1)
我对.rc文件并不熟悉,但这可以在代码中使用:
#!/usr/bin/env python
# example filechooser.py
import pygtk
pygtk.require('2.0')
import gtk
dialog = gtk.FileChooserDialog("Open..", None,
gtk.FILE_CHOOSER_ACTION_OPEN,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
dialog.set_default_response(gtk.RESPONSE_OK)
## here it is
##
for child in dialog.get_children():
for enf in child.get_children():
if isinstance(enf, gtk.HButtonBox):
for butt in enf.get_children():
style = butt.get_style().copy ()
style.bg[gtk.STATE_NORMAL] = butt.get_colormap().alloc (0xffff, 0x0000, 0x0000)
butt.set_style (style)
##
response = dialog.run()
if response == gtk.RESPONSE_OK:
print dialog.get_filename(), 'selected'
elif response == gtk.RESPONSE_CANCEL:
print 'Closed, no files selected'
dialog.destroy()
它会搜索所有对话框的子项以查找按钮并将其样式更改为红色。 希望它能帮到你!