GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Oct 23, 2014 12:40 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Creating Simple PyGTK ComboBox Causes Error
PostPosted: Fri Mar 28, 2014 3:58 am 
Offline
Familiar Face

Joined: Sat Jun 16, 2012 2:20 am
Posts: 5
Hello

I am attempting to create a simple PyGTK ComboBox. But when I run my code I get a runtime error:

Quote:
'comboBox = gtk.ComboBox.new_with_model(client_store)'
AttributeError: type object 'gtk.ComboBox' has no attribute 'new_with_model'


How can I create a PyGTK combobox? Its a very tricky process to create one of these widgets I am finding. Note I am using PyGTK Version 2.24 on Python 2.7

Any advice on how I can create a simple ComboBox would be greatly appreciated.

Code:
    import pygtk
    pygtk.require('2.0')
    import gtk
    gtk.rc_parse('themes/Elegant Brit/gtk-2.0/gtkrc')

    def create_combo_box(self):
       
        client_store = gtk.ListStore(str)
       
        for f in ("a","b","c"):
            client_store.append([f])

        comboBox = gtk.ComboBox.new_with_model(client_store) # Error occurs here
        renderer_text = gtk.CellRendererText()
        comboBox.pack_start(renderer_text, True)
        comboBox.add_attribute(renderer_text, "text", 0)
        return comboBox


Top
 Profile  
 
 Post subject: Re: Creating Simple PyGTK ComboBox Causes Error
PostPosted: Fri Mar 28, 2014 4:58 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 764
Location: UK
Hello,

You are mixing up what methods are available in in PyGTK (v2) and PyGObjects (v3).

Under PyGObjects you can do
Code:
        comboBox = gtk.ComboBox.new_with_model(client_store)
but under PyGTK this should be
Code:
        comboBox = gtk.ComboBox(client_store)

_________________
E.


Top
 Profile  
 
 Post subject: Re: Creating Simple PyGTK ComboBox Causes Error
PostPosted: Fri Mar 28, 2014 5:11 am 
Offline
Familiar Face

Joined: Sat Jun 16, 2012 2:20 am
Posts: 5
Thanks :) That worked


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group