pygtk-Button

button = gtk.Button(label=None, stock=None)

 

 

stock项主要有以下:

STOCK_DIALOG_INFO

STOCK_DIALOG_WARNING

STOCK_DIALOG_ERROR

STOCK_DIALOG_QUESTION

STOCK_DND

STOCK_DND_MULTIPLE

STOCK_ADD

STOCK_APPLY

STOCK_BOLD

STOCK_CANCEL

STOCK_CDROM

STOCK_CLEAR

STOCK_CLOSE

STOCK_CONVERT

STOCK_COPY

STOCK_CUT

STOCK_DELETE

STOCK_EXECUTE

STOCK_FIND

STOCK_FIND_AND_REPLACE

STOCK_FLOPPY

STOCK_GOTO_BOTTOM

STOCK_GOTO_FIRST

STOCK_GOTO_LAST

STOCK_GOTO_TOP

STOCK_GO_BACK

STOCK_GO_DOWN

STOCK_GO_FORWARD

STOCK_GO_UP

STOCK_HELP

STOCK_HOME

STOCK_INDEX

STOCK_ITALIC

STOCK_JUMP_TO

STOCK_JUSTIFY_CENTER

STOCK_JUSTIFY_FILL

STOCK_JUSTIFY_LEFT

STOCK_JUSTIFY_RIGHT

STOCK_MISSING_IMAGE

STOCK_NEW

STOCK_NO

STOCK_OK

STOCK_OPEN

STOCK_PASTE

STOCK_PREFERENCES

STOCK_PRINT

STOCK_PRINT_PREVIEW

STOCK_PROPERTIES

STOCK_QUIT

STOCK_REDO

STOCK_REFRESH

STOCK_REMOVE

STOCK_REVERT_TO_SAVED

STOCK_SAVE

STOCK_SAVE_AS

STOCK_SELECT_COLOR

STOCK_SELECT_FONT

STOCK_SORT_ASCENDING

STOCK_SORT_DESCENDING

STOCK_SPELL_CHECK

STOCK_STOP

STOCK_STRIKETHROUGH

STOCK_UNDELETE

STOCK_UNDERLINE

STOCK_UNDO

STOCK_YES

STOCK_ZOOM_100

STOCK_ZOOM_FIT

STOCK_ZOOM_IN

STOCK_ZOOM_OUT

 

如:

 

#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk
#!/usr/bin/env python
# -*- coding: utf-8 -*-



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

class DeepFuture:
    def blogurlshow(self,widget,data=None):
        print("我的博客:deepfuture.javaeye.com")
    def delwin_event(self,widget,event,data=None):
        #如果你在"delete_event"事件处理中,返回FALSE,GTK会继续发射这个信号,以供destroy,否则返回TRUE,表示这个信号已经被处理,不需要再处理了,也不需要再发射这个信号了,这意味着你不能destroy窗口。
        print("delete event!")
        return False
    def destroy_win(self,widget,data=None):
        #处理窗口销毁信号
        print("destroy event!")        
        gtk.main_quit()
    def __init__(self):
        #创建一个新窗口
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        #指定信号与相关处理事件
        self.window.connect("delete_event", self.delwin_event)			
        self.window.connect("destroy", self.destroy_win)
        self.window.set_border_width(15)
        self.button = gtk.Button("显示我的博客",gtk.STOCK_SAVE_AS)
        self.button.connect("clicked", self.blogurlshow, None)
        self.button.connect_object("clicked", gtk.Widget.destroy,self.window)
        self.window.add(self.button)
        #显示按钮和相关窗口
        self.button.show()
        self.window.show()
    def main(self):
        gtk.main()
if __name__ == "__main__":	
	deep=DeepFuture()
	deep.main()
			
 


 

 

 

带图片的按钮,采用在button内加上box的方式

 

 

#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
 # Create a new hbox with an image and a label packed into it
 # and return the box.

def xpm_label_box(parent, xpm_filename, label_text):
 # Create box for xpm and label
    box1 = gtk.HBox(False, 0)
    box1.set_border_width(2)

     # Now on to the image stuff
    image = gtk.Image()
    image.set_from_file(xpm_filename)
    # Create a label for the button
    label = gtk.Label(label_text)
    # Pack the pixmap and label into the box
    box1.pack_start(image, False, False, 3)
    box1.pack_start(label, False, False, 3)
    image.show()
    label.show()
    return box1

class Buttons:
    # Our usual callback method
    def callback(self, widget, data=None):
        print "Hello again - %s was pressed" % data
    def __init__(self):
    # Create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_title("Image’d Buttons!")
    # It’s a good idea to do this for all windows.
        self.window.connect("destroy", lambda wid: gtk.main_quit())
        self.window.connect("delete_event", lambda a1,a2:gtk.main_quit())
    # Sets the border width of the window.
        self.window.set_border_width(10)
    # Create a new button
        button = gtk.Button()
    # Connect the "clicked" signal of the button to our callback
        button.connect("clicked", self.callback, "cool button")
    # This calls our box creating function
        box1 = xpm_label_box(self.window, "./logo.xpm", "logo button")

    # Pack and show all our widgets
        button.add(box1)

        box1.show()
        button.show()

        self.window.add(button)
        self.window.show()
def main():
    gtk.main()
    return 0

if __name__ == "__main__":
    Buttons()
    main()

 

pygtk-Button

 

 

事件:

 

enter -进入button产生

leave - 离开button产生

pressed - 按下产生

released - 释放产生

clicked - 单击产生

 

 

 

 

你可能感兴趣的:(button)