我用glade创建了一个界面:
from gi.repository import Gtk
class Avvio:
Nome1=["Filippo","Giordano","44","21/06/1955","Impiegato","445554"]
Nome2=["Andrea","Camilli","22","21/05/1990","Studente","656547"]
def accedi(self):
print("ciao")
def cancella(self,button):
print("Cancella elementi")
def build_window():
builder = Gtk.Builder()
builder.add_from_file("Lista.glade")
builder.connect_signals(Avvio())
win=builder.get_object("window1")
return win
if __name__ == '__main__':
win = build_window()
win.connect("delete-event",Gtk.main_quit)
win.show_all()
Gtk.main()
我有两个数组:
Nome1=["Filippo","Giordano","44","21/06/1955","Impiegato","445554"]
Nome2=["Andrea","Camilli","22","21/05/1990","Studente","656547"]
我想将数组插入到glade文件下创建的GTK.Grid中。对于表的每个字段,关联数组的元素。
有可能吗?
我使用了GTK.Grid.attach(),但没有用。
PS这是林间空地文件:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="window1">
<property name="width_request">900</property>
<property name="height_request">400</property>
<property name="can_focus">True</property>
<property name="modal">True</property>
<property name="window_position">center</property>
<child>
<object class="GtkGrid" id="griglia">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">10</property>
<property name="margin_right">10</property>
<property name="margin_top">10</property>
<property name="row_homogeneous">True</property>
<property name="column_homogeneous">True</property>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">Esci</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="receives_default">True</property>
<property name="halign">start</property>
<property name="valign">center</property>
<property name="margin_left">10</property>
</object>
<packing>
<property name="left_attach">3</property>
<property name="top_attach">6</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button2">
<property name="label" translatable="yes">Cancella Tutto</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="receives_default">True</property>
<property name="opacity">0.98999999999999999</property>
<property name="halign">start</property>
<property name="valign">center</property>
<property name="margin_left">10</property>
<signal name="pressed" handler="cancella" swapped="no"/>
</object>
<packing>
<property name="left_attach">3</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="width_request">0</property>
<property name="height_request">0</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkViewport" id="viewport1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkGrid" id="grid2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">3</property>
<property name="column_homogeneous">True</property>
<child>
<object class="GtkLabel" id="Nome">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Nome</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="Cognome">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Cognome</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="Età">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Età</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="Data">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Data di Nascita</property>
</object>
<packing>
<property name="left_attach">3</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="Profes">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Professione</property>
</object>
<packing>
<property name="left_attach">4</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="Tutti">
<property name="label" translatable="yes">Sel. Tutti</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="receives_default">False</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="left_attach">6</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="Matricola">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Matricola</property>
</object>
<packing>
<property name="left_attach">5</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="width">3</property>
<property name="height">7</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label8">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Inserimento Dati in Tabella</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">7</property>
<property name="width">4</property>
<property name="height">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
</interface>