我开始学习使用gtk +创建ui的python3。
所以我想在点击按钮时让spinner开始在我的ui中工作,但点击按钮时没有任何反应
如果我按照GTK +教程,微调器工作正常。但我喜欢在我的代码中使用类我喜欢这里的sugestion(http://python-gtk-3-tutorial.readthedocs.org/en/latest/builder.html#example)来使一些类在connect_signals中调用动作
有人可以帮帮我吗?我的python代码:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
try:
from gi.repository import Gtk
except ImportError:
print >> sys.stderr, 'ERRO: requer a lib python3-gi'
sys.exit(1)
require_version('Gtk', '3.0')
class application:
def __init__(self):
self.builder = Gtk.Builder()
self.builder.add_from_file("stack.glade")
self.builder.connect_signals(actions())
self.spinner = self.builder.get_object("spinner1")
def spinner_start(self):
self.spinner.start()
class actions:
def onDeleteWindow(self, *args):
Gtk.main_quit(*args)
def onButtonClick(self, widget, button="button1"):
application().spinner_start()
if __name__ == "__main__":
main = application()
window = main.builder.get_object("window1")
window.show()
Gtk.main()
我的林间文件:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkEntry" id="entry1">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">button</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="onButtonClick" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkSpinner" id="spinner1">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>
</interface>