Lo siguiente es un ejemplo mínimo de cómo se usa el widget gtk.IconView, añadiendo iconos desde ficheros nuestros (sin usar los iconos de stock). Para ver cómo usar los iconos de stock puedes consultar (Py)GTK Tips 'n Tricks
import gobject
import pygtk
import gtk
import gtk.glade
import gtk.gdk

# creo el iconview
iconview = gtk.IconView()
iconview.set_orientation(gtk.ORIENTATION_HORIZONTAL)

# le indico qué columna del liststore tiene el texto, y cuál el icono
iconview.set_text_column(1)
iconview.set_pixbuf_column(0)

# pongo un scrolledwindow, para que quede más bonito
scroll = gtk.ScrolledWindow()
scroll.set_policy(gtk.POLICY_ALWAYS, gtk.POLICY_ALWAYS)

# defino los tipos a representar
liststore = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING)

# creo los iconos
debian  = gtk.gdk.pixbuf_new_from_file("debian-icon.png")
apple   = gtk.gdk.pixbuf_new_from_file("apple-icon.png")
windows = gtk.gdk.pixbuf_new_from_file("windows-icon.png")
fedora  = gtk.gdk.pixbuf_new_from_file("fedora-icon.png")

# añado los datos al liststore
liststore.append([debian, "string 1"])
liststore.append([fedora, "string 2"])
liststore.append([windows, "string 3"])
liststore.append([apple, "string 4"])
liststore.append([debian, "string 1"])
liststore.append([fedora, "string 2"])
liststore.append([windows, "string 3"])
liststore.append([apple, "string 4"])
liststore.append([debian, "string 1"])
liststore.append([fedora, "string 2"])
liststore.append([windows, "string 3"])
liststore.append([apple, "string 4"])
liststore.append([debian, "string 1"])
liststore.append([fedora, "string 2"])
liststore.append([windows, "string 3"])
liststore.append([apple, "string 4"])

iconview.set_model(liststore)
scroll.add(iconview)

win = gtk.Window()
win.resize(320, 240)
win.add(scroll)
win.show_all()

gtk.main()


blog comments powered by Disqus