Glade Python : Image Viewer
Glade Python : Image Viewer
(Screen Shot)
Python Glade Image Viewer :
import os
import sys
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gio, GdkPixbuf
class Handler:
def OpenButtonClick(self,button):
dialog = Gtk.FileChooserDialog("Choose a Image",
None,
Gtk.FileChooserAction.OPEN,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
dialog.set_default_size(600, 300)
response = dialog.run()
if response == Gtk.ResponseType.OK:
pic = dialog.get_filename()
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(pic,400,400,True)
x.builder.get_object("image1").set_from_pixbuf(pixbuf)
elif response == Gtk.ResponseType.CANCEL:
print("Cancel")
dialog.destroy()
class Example:
def __init__(self):
self.builder=Gtk.Builder()
self.builder.add_from_file("ImageViewer.glade")
self.builder.connect_signals(Handler())
window=self.builder.get_object("window1")
window.show_all()
def main(self):
Gtk.main()
x=Example()
x.main()
***************** End Project ********************
(Screen Shot)
Python Glade Image Viewer :
import os
import sys
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gio, GdkPixbuf
class Handler:
def OpenButtonClick(self,button):
dialog = Gtk.FileChooserDialog("Choose a Image",
None,
Gtk.FileChooserAction.OPEN,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
dialog.set_default_size(600, 300)
response = dialog.run()
if response == Gtk.ResponseType.OK:
pic = dialog.get_filename()
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(pic,400,400,True)
x.builder.get_object("image1").set_from_pixbuf(pixbuf)
elif response == Gtk.ResponseType.CANCEL:
print("Cancel")
dialog.destroy()
class Example:
def __init__(self):
self.builder=Gtk.Builder()
self.builder.add_from_file("ImageViewer.glade")
self.builder.connect_signals(Handler())
window=self.builder.get_object("window1")
window.show_all()
def main(self):
Gtk.main()
x=Example()
x.main()
***************** End Project ********************
Comments
Post a Comment