[pygtk] How to change the alpha (opacity or transparency)of an image?
李志
lizhi5261 at 163.com
Fri Apr 15 15:19:22 WST 2011
Hi, everyone.
How can I to change the alpha of an image? The code sample is as follows.
import pygtk
pygtk.require('2.0')
import gtk
class ImagesExample:
# when invoked (via signal delete_event), terminates the application.
def close_application(self, widget, event, data=None):
gtk.main_quit()
return False
def __init__(self):
# create the main window, and attach delete_event signal to terminating
# the application
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.connect("delete_event", self.close_application)
window.set_border_width(10)
window.show()
# a horizontal box to hold the buttons
hbox = gtk.HBox()
hbox.show()
window.add(hbox)
pixbuf = gtk.gdk.pixbuf_new_from_file("Button-Last-72x72.png")
print pixbuf.get_n_channels()
print pixbuf.get_has_alpha()
image = gtk.Image()
image.set_from_pixbuf(pixbuf)
image.show()
print image.get_window()
hbox.pack_start(image)
def main():
gtk.main()
return 0
if __name__ == "__main__":
ImagesExample()
main()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.daa.com.au/pipermail/pygtk/attachments/20110415/ce06e3fb/attachment.html>
More information about the pygtk
mailing list