作为一个新手,我正在尝试使用 Glade 和 python 创建一个基本的主题安装程序。一切正常,但我无法在任何地方找到如何为 gtkFileChooserButton 使用 get_filename() 方法。我的 Glade 文件看起来像这样。
<?xml version="1.0"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkWindow" id="main">
<property name="title" translatable="yes">Maininin</property>
<property name="window_position">center</property>
<signal name="destroy" handler="on_main_destroy"/>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<child>
<object class="GtkLabel" id="INFO">
<property name="visible">True</property>
<property name="label" translatable="yes">Theme</property>
</object>
<packing>
<property name="expand">False</property>
<property name="padding">28</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHButtonBox" id="hbuttonbox1">
<property name="visible">True</property>
<property name="layout_style">spread</property>
<child>
<object class="GtkFileChooserButton" id="DD">
<property name="visible">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkHButtonBox" id="hbuttonbox2">
<property name="visible">True</property>
<property name="layout_style">spread</property>
<child>
<object class="GtkButton" id="Add">
<property name="label">gtk-add</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_Add_clicked"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="Quit">
<property name="label">gtk-quit</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_Quit_clicked"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="WARN">
<property name="visible">True</property>
<property name="label" translatable="yes">Warning</property>
</object>
<packing>
<property name="expand">False</property>
<property name="padding">37</property>
<property name="position">3</property>
</packing>
</child>
</object>
</child>
`
Python代码是:
import sys
try:
import pygtk
pygtk.require("2.0")
except:
pass
try:
import gtk
except:
print("GTK Not Availible")
sys.exit(1)
class workplz(object):
def __init__( self ):
builder = gtk.Builder()
builder.add_from_file("heme.glade")
builder.connect_signals({"on_main_destroy" : self.quit, "on_Add_clicked" : self.add, "on_Quit_clicked" : self.quit})
self._window = builder.get_object("main")
self._window.show()
def add(self, widget):
target=DD.get_filename()
print target
def quit(self, widget):
sys.exit(0)
if __name__ == "__main__":
wine = workplz()
gtk.main()
什么是正确的做法???