2016-07-22 8 views
2

私はPython GTK + 3を使用しています。ボタン信号でGtkGridにデータを追加することはできません(信号でattachメソッドを呼び出すと何も起こりません)。コードは次のとおりです。GtkGridの動的データ

# -*- coding: utf-8 -*- 
from gi.repository import Gtk, GObject, Gdk 
import sqlite3 

class MainWindow(Gtk.Window): 

def __init__(self): 
    Gtk.Window.__init__(self, title="1") 
    self.fullscreen() 
    MainBox = Gtk.Box() 
    MainBox.set_orientation(Gtk.Orientation.VERTICAL) 
    self.add(MainBox) 
    self.table = Gtk.Grid() 
    self.table.set_column_spacing(10) 
    MainBox.pack_start(self.table, False, True, 0) 
    btn_add = Gtk.Button("ADD VALS") 
    btn_add.connect("clicked", self.add_kopd) 
    MainBox.pack_start(btn_add, False, True, 0) 
    self.table.attach(Gtk.Label("1"), 0,0,1,1) 
    self.table.attach(Gtk.Label("2"), 1,0,1,1) 
    self.table.attach(Gtk.Label("3"), 2,0,1,1) 

def add_kopd(self, widget): 
    self.table.attach(Gtk.Label("4"), 0,1,1,1) 
    self.table.attach(Gtk.Label("5"), 1,1,1,1) 
    self.table.attach(Gtk.Label("6"), 2,1,1,1) 

win = MainWindow() 
win.connect("delete-event", Gtk.main_quit) 
win.show_all() 
Gtk.main() 

答えて

2

表示する新しいウィジェットを設定する必要があります。 GTKでは、デフォルトで何も表示されません。あなたはSHOW_ALL()

def add_kopd(self, widget): 
    window, attachment = self.table.attach(Gtk.Label("4"), 0,1,1,1) 
    attachment.show() 
    ... 
を呼び出すにしたくない場合は、

def add_kopd(self, widget): 
    self.table.attach(Gtk.Label("4"), 0,1,1,1) 
    self.table.attach(Gtk.Label("5"), 1,1,1,1) 
    self.table.attach(Gtk.Label("6"), 2,1,1,1) 
    self.show_all() 

をまたは:これにあなたのadd_kopd方法を変更します。