next up previous contents
Next: Signals, Events and Functions Up: PyGTK Previous: PyGTK 除錯   Contents

Buttons 與 Layout

  1. Example
    #!/usr/bin/python
    # coding: utf-8
    
    #import pygtk
    import gtk
    
    class myPy:
        def __init__(self):
            window = gtk.Window(gtk.WINDOW_TOPLEVEL)
            "lambda 是匿名函式 x 為其參數"
            window.connect("destroy", lambda x: gtk.main_quit())
            window.set_title('視窗抬頭')
            window.set_keep_above(True)
    
            vbox1 = gtk.VBox(False, 2)
            "homogeneous=True 則內含物件平均分佈,spaceing=5 間隔5"
            hbox1 = gtk.HBox(homogeneous=True,spacing=5)
            hbox2 = gtk.HBox(homogeneous=True,spacing=5)
            hbox3 = gtk.HBox(homogeneous=True,spacing=5)
            yes = gtk.Button("yes")
            no = gtk.Button("no")
            close = gtk.Button(None,gtk.STOCK_CLOSE)
            hbox1.add(yes)
            hbox1.add(no)
            hbox2.add(close)
            vbox1.pack_start(hbox1, True, True, 0)
            vbox1.pack_start(hbox2, True, True, 0)
            vbox1.pack_start(hbox3, True, True, 0)
            window.add(vbox1)
    
            window.show_all()
    
    myPy()
    gtk.main()
    
  2. 類別相關聯結
    1. gtk.Vbox class
    2. gtk.Box class
    3. gtk.Hbox class
    4. gtk.Button class
    5. Stock Items



2017-06-14