This site has been retired. For up to date information, see handbook.gnome.org or gitlab.gnome.org.


[Home] [TitleIndex] [WordIndex

PyGTK is unmaintained and has been archived. It has been superseded by PyGObject. Links below might not work anymore and information below might be incorrect.

label.get_text() Vs. label.get_label()

   1 >>> import gtk
   2 >>> label = gtk.Label()
   3 >>> label.set_markup("<b>Hello</b>")
   4 >>> label.get_label()
   5 '<b>Hello</b>'
   6 >>> label.get_text()
   7 'Hello'

Connecting and diconnecting a signal to widget

   1 >>> import gtk
   2 >>> button = gtk.Button("Yes")
   3 >>> def on_button_clicked(*args):
   4 ...     print args
   5 ... 
   6 >>> handler = button.connect("clicked", on_button_clicked)
   7 >>> print handler #prints handler id
   8 4
   9 >>> button.emit("clicked")
  10 (<gtk.Button object (GtkButton) at 0x40228c34>,)
  11 >>> button.disconnect(handler)
  12 >>> button.emit("clicked")
  13 >>> 

Sub classing and simple overriding of methods

   1 >>> import gtk
   2 >>> class MyEntry(gtk.Entry):
   3 ...     def set_text(self, text):
   4 ...             gtk.Entry.set_text(self, "Hello, %s" % text) 
   5 ... 
   6 >>> entry = MyEntry()
   7 >>> entry.set_text("World!")
   8 >>> entry.get_text()
   9 'Hello, World!'

2024-10-23 11:37