PyGobject error
<pre><code>#!/usr/bin/python
# -*- coding: utf-8 -*-
from gi.repository import Gtk
class ourwindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="My Hello World Program")
Gtk.Window.set_default_size(self, 400,325)
Gtk.Window.set_position(self, Gtk.WindowPosition.CENTER)
button1 = Gtk.Button("Hello, World!")
button1.connect("clicked", self.whenbutton1_clicked)
self.add(button1)
def whenbutton1_clicked(self, button):
print "Hello, World!"
window = ourwindow()        
window.connect("delete-event", Gtk.main_quit)
window.show_all()
Gtk.main()
</code></pre>

<p>This Python+GTK code is giving me the following error:</p>

<pre><code>./pygtk.py
./pygtk.py:3: PyGIWarning: Gtk was imported without specifying a version      first. Use gi.require_version('Gtk', '3.0') before import to ensure that the right version gets loaded.
 from gi.repository import Gtk
 Traceback (most recent call last):
 File "./pygtk.py", line 4, in &lt;module&gt;
 class ourwindow(Gtk.Window):
 File "./pygtk.py", line 10, in ourwindow
 button1.connect("clicked", self.whenbutton1_clicked)
 NameError: name 'self' is not defined
</code></pre>

<p>It also gives me an indentaion error.
I am new to Python and GTK.
Thanks in advance.</p>

<p>This is most likely how it should be formatted:</p>

<pre><code>#!/usr/bin/python
# -*- coding: utf-8 -*-
from gi.repository import Gtk

class ourwindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="My Hello World Program")
        Gtk.Window.set_default_size(self, 400,325)
        Gtk.Window.set_position(self, Gtk.WindowPosition.CENTER)
        button1 = Gtk.Button("Hello, World!")
        button1.connect("clicked", self.whenbutton1_clicked)
        self.add(button1)

    def whenbutton1_clicked(self, button):
        print "Hello, World!"

window = ourwindow()        
window.connect("delete-event", Gtk.main_quit)
window.show_all()
Gtk.main()
</code></pre>

<p>I would definitely recommend you to read some basic Python tutorial to at least understand the syntax. Easier to do GUI stuff when you know the basics of the language.</p>

python gtk pygobject