Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: AttributeError: 'module' object has no attribute 'Hbox'

  1. #1
    Join Date
    Aug 2007
    Location
    Arvada, CO
    Beans
    275
    Distro
    Ubuntu 10.10 Maverick Meerkat

    AttributeError: 'module' object has no attribute 'Hbox'

    I'm still muddling my way through the PyGTK tutorial in my spare moments. I've come across an interesting error and search engines have been of no help narrowing it down.

    Here's the code, typed verbatim from the tutorial sans comments:

    Code:
    #!/usr/bin/env python
    
    import pygtk
    import gtk
    
    class HelloWorld2:
    	def callback(self, widget, data):
    		print "Hello again - %s was pressed." % data
    
    	def delete_event(self, widget, event, data=None):
    		gtk.main.quit()
    		return False
    
    	def __init__(self):
    		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    		self.window.set_title("Hello Buttons!")
    		self.window.connect("delete_event", self.delete_event)
    		self.window.set_border_width(10)
    		self.box1 = gtk.Hbox(False, 0)
    		self.window.add(self.box1)
    		self.button1 = gtk.Button("Button 1")
    		self.button2 = gtk.Button("Button 2")
    		self.button1.connect("clicked", self.callback, "button number 1")
    		self.button2.connect("clicked", self.callback, "button number 2")
    		self.box1.pack_start(self.button1, True, True, 0)
    		self.box1.pack_start(self.button2, True, True, 0)
    		self.button1.show()
    		self.button2.show()
    		self.box1.show()
    		self.window.show()
    
    	def main():
    		gtk.main()
    
    if __name__ == "__main__":
    	hello = HelloWorld2()
    	main()
    And here's the resulting error message when I run it in the terminal after making it executable:

    Code:
    Traceback (most recent call last):
      File "./Upgraded Hello World.py", line 37, in <module>
        hello = HelloWorld2()
      File "./Upgraded Hello World.py", line 20, in __init__
        self.box1 = gtk.Hbox(False, 0)
    AttributeError: 'module' object has no attribute 'Hbox'
    I'm importing gtk; I cannot imagine why the python interpreter would think there was no such thing as an HBox. I've looked this error up everywhere I know to, but it's apparently not a common one.

    Any leads on how to track this one down would be duly appreciated. You guys are spoiling me with all your recent help.

  2. #2
    Join Date
    Apr 2006
    Location
    Slovenia
    Beans
    370
    Distro
    Ubuntu Development Release

    Re: AttributeError: 'module' object has no attribute 'Hbox'

    As you said it - I also cannot imagine why the python interpreter would think there was no such thing as an HBox. But... in the example you typed:

    Code:
    self.box1 = gtk.Hbox(False, 0)
    should be (just to be clear):
    Code:
    self.box1 = gtk.HBox(False, 0)

  3. #3
    Join Date
    Aug 2007
    Location
    Arvada, CO
    Beans
    275
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: AttributeError: 'module' object has no attribute 'Hbox'

    Thanks - I'll have to try that when I get a minute. If that fixes the problem I'll have to sit down and have a good cry, I think.

  4. #4
    Join Date
    Nov 2007
    Location
    Holland
    Beans
    16
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: AttributeError: 'module' object has no attribute 'Hbox'

    I've been busy with PyGTK too, and I seem to have some sort of related problem.
    If I take the following code posted by Carl Hamlin, with the Hbox/HBox fix ofcourse, I get a related message.
    My current code is as following:
    Code:
    #!/usr/bin/env python
    
    import pygtk
    import gtk
    
    class HelloWorld2:
    	def callback(self, widget, data):
    		print "Hello again - %s was pressed." % data
    
    	def delete_event(self, widget, event, data=None):
    		gtk.main.quit()
    		return False
    
    	def __init__(self):
    		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    		self.window.set_title("Hello Buttons!")
    		self.window.connect("delete_event", self.delete_event)
    		self.window.set_border_width(10)
    		self.box1 = gtk.HBox(False, 0)
    		self.window.add(self.box1)
    		self.button1 = gtk.Button("Button 1")
    		self.button2 = gtk.Button("Button 2")
    		self.button1.connect("clicked", self.callback, "button number 1")
    		self.button2.connect("clicked", self.callback, "button number 2")
    		self.box1.pack_start(self.button1, True, True, 0)
    		self.box1.pack_start(self.button2, True, True, 0)
    		self.button1.show()
    		self.button2.show()
    		self.box1.show()
    		self.window.show()
    
    	def main():
    		gtk.main()
    
    if __name__ == "__main__":
    	hello = HelloWorld2()
    	main()
    So, I make it executable and run it in the Terminal and it produces this:
    Code:
    Traceback (most recent call last):
      File "./gtk.py", line 36, in <module>
        hello = HelloWorld2()
      File "./gtk.py", line 15, in __init__
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    AttributeError: 'module' object has no attribute 'Window'
    This is quite strange as I just read in the documentation that it should be excactly the same!

    I've already tried reinstalling python-gtk2 and python-gnome2-extras and such things, but it didn't help.
    What should I do? Am I missing a very obvious typo or is my PyGTK install screwed up or is it something else?

  5. #5
    Join Date
    Nov 2007
    Location
    Holland
    Beans
    16
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: AttributeError: 'module' object has no attribute 'Hbox'

    Does anyone have an idea of what it could be?

  6. #6
    Join Date
    May 2007
    Beans
    251

    Re: AttributeError: 'module' object has no attribute 'Hbox'

    It seems to be working for me - with minor modifications..

    1. The quit part is gtk.main_quit() and not gtk.main.quit().
    2. The main() function is under the class level - so, you either pull it out of class by de-indenting it OR make it a class method by accepting the self ref. in it and calling it as 'hello.main()' instead of just 'main()'
    The Unforgiven

  7. #7
    Join Date
    Jun 2007
    Beans
    692

    Re: AttributeError: 'module' object has no attribute 'Hbox'

    Quote Originally Posted by maarten12 View Post
    So, I make it executable and run it in the Terminal and it produces this:
    Code:
    Traceback (most recent call last):
      File "./gtk.py", line 36, in <module>
        hello = HelloWorld2()
      File "./gtk.py", line 15, in __init__
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    AttributeError: 'module' object has no attribute 'Window'
    Name your file something other than gtk.py. Trying to import a module with the same name as your executable causes errors like the one you see there.

  8. #8
    Join Date
    Feb 2007
    Beans
    521
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: AttributeError: 'module' object has no attribute 'Hbox'

    Code:
    gtk.HBox()
    Code:
    gtk.main_quit()
    And the last line should be
    Code:
    gtk.main()
    or
    Code:
    hello.main()
    The "main" method of the HelloWorld2 class should be:
    Code:
    	def main(self):
    		gtk.main()
    (note the "self". In classes, self is always the first argument)
    Last edited by spupy; February 24th, 2009 at 10:34 PM.
    make install - not war!

    Oh hai!

  9. #9
    Join Date
    Dec 2009
    Beans
    1

    Re: AttributeError: 'module' object has no attribute 'Hbox'

    def start (self):
    global db
    db=MySQLdb.Connect(host="localhost",user="root",pa sswd="12345",db="example")
    global cursor
    cursor=db.cursor
    number=int(self.ui.lineEdit_5.text())

    password=int(self.ui.lineEdit_6.text())

    sql="select no from admin where number='no' and pasword='pasword'"
    result=self.cursor.execute(sql)
    if result==1 and self.ui.teacher.isChecked ():
    QtGui.QApplication.exit (1)

    elif result==1 and self.ui.ylisans.isChecked ():
    QtGui.QApplication.exit (2)

    elif result==1 and self.ui.lisans.isChecked ():
    QtGui.QApplication.exit (3)


    the code is given

    Traceback (most recent call last):
    File "/home/eng/Desktop/i.py", line 25, in start
    number=int(self.ui.lineEdit_5.text())
    ValueError: invalid literal for int() with base 10: ''
    Traceback (most recent call last):
    File "/home/eng/Desktop/i.py", line 30, in basla
    number=self.Cursor.execute(sql)
    AttributeError: 'singnal' object has no attribute 'Cursor'

    help me please

  10. #10
    Join Date
    Aug 2007
    Location
    127.0.0.1
    Beans
    1,800
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: AttributeError: 'module' object has no attribute 'Hbox'

    Quote Originally Posted by eng.sfft View Post
    def start (self):
    global db
    db=MySQLdb.Connect(host="localhost",user="root",pa sswd="12345",db="example")
    global cursor
    cursor=db.cursor
    number=int(self.ui.lineEdit_5.text())

    password=int(self.ui.lineEdit_6.text())

    sql="select no from admin where number='no' and pasword='pasword'"
    result=self.cursor.execute(sql)
    if result==1 and self.ui.teacher.isChecked ():
    QtGui.QApplication.exit (1)

    elif result==1 and self.ui.ylisans.isChecked ():
    QtGui.QApplication.exit (2)

    elif result==1 and self.ui.lisans.isChecked ():
    QtGui.QApplication.exit (3)


    the code is given

    Traceback (most recent call last):
    File "/home/eng/Desktop/i.py", line 25, in start
    number=int(self.ui.lineEdit_5.text())
    ValueError: invalid literal for int() with base 10: ''
    Traceback (most recent call last):
    File "/home/eng/Desktop/i.py", line 30, in basla
    number=self.Cursor.execute(sql)
    AttributeError: 'singnal' object has no attribute 'Cursor'

    help me please
    You should be more specific, and this thread is about PyGTK, not PyQT and MySQL.

    Start another thread.
    "Just in terms of allocation of time resources, religion is not very efficient. There's a lot more I could be doing on a Sunday morning."
    -Bill Gates

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •