python list widget pygtk clist

tkinter text in python 3



El widget de clonación de Python no devuelve la lista esperada, solo devuelve el primer carácter de cada elemento (1)

Cuando agregas datos a CList a través del método de agregar, debes pasar una secuencia. Reescribe tu código:

def button_add_clicked(self, data): dirList = os.listdir("/usr/bin") for item in dirList: if not item.startswith(''.''): data.append([item]) data.sort()

Cuando creas una instancia de CList pasas al número de compilaciones del constructor. En su ejemplo, creó CList con una columna, por eso puede ver solo el primer elemento (primer carácter) de la secuencia pasada en el método de agregar.

Escribí un programa simple para imprimir todos los archivos y subdirectorios no ocultos en un directorio determinado.

Ahora estoy tratando de migrar mi código a un ejemplo de widget clist que encontré en Google. Además de eliminar algunos botones innecesarios, todo lo que modifiqué fue la parte superior para integrar mi código, y funciona parcialmente, excepto que solo devuelve el primer carácter de cada archivo y subdirectorio. Así que esperaba esto:

Desktop Downloads Scripts textfile.txt pron.avi

Pero en cambio tengo esto:

D D S t p

Aquí está el ejemplo con el código que cambié (realmente solo la primera definición)

import gtk, os class CListExample: # this is the part Thraspic changed (other than safe deletions) # User clicked the "Add List" button. def button_add_clicked(self, data): dirList=os.listdir("/usr/bin") for item in dirList: if item[0] != ''.'': data.append(item) data.sort() return def __init__(self): self.flag = 0 window = gtk.Window(gtk.WINDOW_TOPLEVEL) window.set_size_request(250,150) window.set_title("GtkCList Example") window.connect("destroy", gtk.mainquit) vbox = gtk.VBox(gtk.FALSE, 5) vbox.set_border_width(0) window.add(vbox) vbox.show() scrolled_window = gtk.ScrolledWindow() scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS) vbox.pack_start(scrolled_window, gtk.TRUE, gtk.TRUE, 0) scrolled_window.show() clist = gtk.CList(1) # What however is important, is that we set the column widths as # they will never be right otherwise. Note that the columns are # numbered from 0 and up (to an anynumber of columns). clist.set_column_width(0, 150) # Add the CList widget to the vertical box and show it. scrolled_window.add(clist) clist.show() hbox = gtk.HBox(gtk.FALSE, 0) vbox.pack_start(hbox, gtk.FALSE, gtk.TRUE, 0) hbox.show() button_add = gtk.Button("Add List") hbox.pack_start(button_add, gtk.TRUE, gtk.TRUE, 0) # Connect our callbacks to the three buttons button_add.connect_object("clicked", self.button_add_clicked, clist) button_add.show() # The interface is completely set up so we show the window and # enter the gtk_main loop. window.show() def main(): gtk.mainloop() return 0 if __name__ == "__main__": CListExample() main()