TypeError :object of type 'GtkSpinner' doe

2019-08-31 02:51发布

问题:

I am learning about Spinners in PyGtk. I executed this program :

#!/usr/bin/env python

import gtk

class Spinner:
    def __init__(self):
        window=gtk.Window()
        window.set_default_size(200,200)

        vbox = gtk.VBox(False, 5)
        hbox = gtk.HBox(True, 5)

        self.spinner = gtk.Spinner()
        self.spinner.set_property("num-steps", 10)

        button_start = gtk.Button("Start")
        button_stop = gtk.Button("Stop")

        window.connect("destroy", lambda q : gtk.main_quit())
        button_start.connect("clicked", self.start_animation)
        button_stop.connect("clicked", self.stop_animation)

        window.add(vbox)
        vbox.pack_start(self.spinner,True,True,0)
        vbox.pack_end(hbox, False, False, 0)
        hbox.pack_start(button_start)
        hbox.pack_start(button_stop)

        window.show_all()

    def start_animation(self, widget):
        self.spinner.start()

    def stop_animation(self, widget):
        self.spinner.stop()

Spinner()
gtk.main()

Shell threw the following error:

Traceback (most recent call last):
  File "spinner.py", line 37, in <module>
    Spinner()
  File "spinner.py", line 14, in __init__
    self.spinner.set_property("num-steps", 10)
TypeError: object of type `GtkSpinner' does not have property `num-steps'

It throws a similar error in the case of cycle-duration property of Spinner. Where am I going wrong?