我在Ubiuntu 14.04 LTS上使用pyGtk和Glade(3.16.1)在python 2.7中创建了一个简单的应用程序框架。 我添加了一个ToolBar和一些按钮,但gtkToolButton总是被禁用。如何从Glade启用它们?
my gui with toolbutton disabled
我在python中也尝试使用“set_sensitive”,但没有任何作用。
你能帮帮我吗?非常感谢你!这是来自glade文件的片段:
<child>
<object class="GtkToolbar" id="toolbar1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="toolbar_style">both-horiz</property>
<property name="show_arrow">False</property>
<style>
<class name="primary-toolbar"/>
</style>
<child>
<object class="GtkToolButton" id="toolbutton1">
<property name="name">bt1</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="is_important">True</property>
<property name="action_name">bt1</property>
<property name="label" translatable="yes">toolbutton1</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-connect</property>
<signal name="clicked" handler="on_toolbutton1_clicked" swapped="no"/>
</object>
答案 0 :(得分:0)
GtkToolbars使用起来不是很简单。您必须创建相应的操作。这是一个如何使用它们的简单示例:
林间空地文件:
<interface>
<requires lib="gtk+" version="3.16"/>
<object class="GtkWindow" id="window">
<property name="can_focus">False</property>
<child>
<object class="GtkToolbar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkToolButton">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="action_name">app.zoom</property>
<property name="label" translatable="yes">zoom</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-zoom-in</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
python文件:
from gi.repository import Gtk, Gio
class Application(Gtk.Application):
def do_activate(self):
action = Gio.SimpleAction.new('zoom', None)
action.connect('activate', self.on_zoom)
self.add_action(action)
builder = Gtk.Builder.new_from_file('window.glade')
window = builder.get_object('window')
window.show_all()
self.add_window(window)
def on_zoom(self, action, param):
print('clicked')
if __name__ == '__main__':
Application().run()
你也可以看一下类似的example for the application menu