0

I have this code to add table inside VBox which is not working

topwid=gtk.VBox(gtk.FALSE, 0)

table = gtk.Table(3, 3, True)
topwid.pack_start(table)

how to do this?

Source code(GUI part):

def build_gui(self):
    self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    self.window.connect("delete_event", self.gotoTray)
    self.window.connect("destroy", self.destroy)
    self.window.set_border_width(24)
    self.window.set_size_request(400, 200)
    self.window.set_title("xyz client")
    self.window.set_position(gtk.WIN_POS_CENTER_ALWAYS)
    self.window.set_resizable(False)

    topwid=gtk.VBox(gtk.FALSE, 0)

    table = gtk.Table(3, 3, True)
    topwid.pack_start(table)

    label = gtk.Label("Username")
    table.attach(label,0,1,0,1)
    label.show()

    self.username=gtk.Entry(max=10)
    table.attach(self.username,1,3,0,1)
    self.username.show()

    label1 = gtk.Label("Password")
    table.attach(label1,0,1,1,2)
    label1.show()

    self.password=gtk.Entry(max=10)
    table.attach(self.password,1,3,1,2)
    self.password.set_visibility(False)
    self.password.show()

    self.button=gtk.Button("Login")
    self.button.connect("clicked",self.click_button)
    table.attach(self.button,1,3,2,3)
    self.button.show()

    #

    table.show()

    mb = gtk.MenuBar()

    filemenu = gtk.Menu()
    filem = gtk.MenuItem("File")
    filem.set_submenu(filemenu)

    exit = gtk.MenuItem("Exit")
    exit.connect("activate", gtk.main_quit)
    filemenu.append(exit)

    mb.append(filem)
    vbox = gtk.VBox(False, 2)
    vbox.pack_start(mb, False, False, 0)
    topwid.pack_start(vbox)

    topwid.show()

    self.statusicon = gtk.status_icon_new_from_stock(gtk.STOCK_NETWORK)
    self.statusicon.connect('activate', self.status_clicked )
    self.statusicon.set_name("Cyberoam")

    self.window.show_all()

    gtk.main()
4

1 回答 1

1

Could do with seeing some more of the source code to really be sure but are you calling show_all on the window object?

Below is an example of it working.

import pygtk
pygtk.require('2.0')
import gtk

class Base:
    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        vbox=gtk.VBox(False, 0)

        table = gtk.Table(3, 3, True)
        table.attach(gtk.Button("1"), 0, 1, 0, 1)
        vbox.pack_start(table)

        self.window.add(vbox)

        self.window.show_all()

  def main(self):
      gtk.main()

if __name__ == "__main__":
    base = Base()
    base.main()
于 2012-06-02T14:47:37.980 回答