Hey Guys!
Today I programmed some lines of pygtk code. Everything was fine until I tried to rename, resave, or even copy and paste my python-file. When I do that, I get the following error message:
Quote:
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
AttributeError: 'module' object has no attribute 'Window'
Only the original file works and I really have NO clue whats wrong about the others.
I trimmed my code to be easier to read - still the same error occurs of course:
Code:
import pygtk
pygtk.require('2.0')
import gtk
class Base:
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_position(gtk.WIN_POS_CENTER)
self.window.set_size_request(200,160)
self.window.set_title("kb-handler")
self.button1 = gtk.Button("Exit")
self.button1.connect("clicked",self.close)
fixed = gtk.Fixed()
fixed.put(self.button1,20,350)
self.window.add(fixed)
self.window.show_all()
self.window.connect("destroy",self.close)
def close(self,widget,data=None):
print "Closed"
gtk.main_quit()
def main(self):
gtk.main()
if __name__ == "__main__":
base = Base()
base.main()
I'm sorry, but I can't tell you what version of PyGTK I really use. I installed PyGTK with PyCairo and PyGObject via a all in one installation from this website:
http://www.pygtk.org/downloads.htmlThe version number of the package I used is 2.24.2 which is a 32bit Python 2.7 version.
As mentioned, I especially don't understand why the original version works and the renamed or saved ones not. I allready tried to figure out whats wrong about my code and it seems that this problem is not that uncommon. But the usual problems are:
- typing errors
- the file name is also the name of an imported modul (which is obviously not the case because I named them version1, version2,...)
- wrong versions of PyGTK,... (which to my opinion is also not the case, because the original version works)
I really hope you can help me, I would be very greatful.
Thank's a lot guys!
Joe