You are not logged in.
Pages: 1
I'm trying to write an app in python with glade. Anyone know if I can make an image preview box? e.g. take a location as a variable from python and then display the image from that location
Or am I going to have to do that in full PyGTK?
Offline
You mean this?
#!/usr/bin/ env python
""" Display an image inside my window """
import wx
class Frame(wx.Frame):
""" Frame class from wx that displays the image """
def __init__(self, image, parent= None, id= -1, pos= wx.DefaultPosition, title= "See my picture"):
""" Create a Frame instance and display the image """
temp = image.ConvertToBitmap()
size = temp.GetWidth(), temp.GetHeight()
wx.Frame.__init__(self, parent, id, title, pos, size)
self.bmp = wx.StaticBitmap(parent = self, bitmap = temp)
class App(wx.App):
""" Application Class """
def OnInit(self):
image = wx.Image('wall.jpg',wx.BITMAP_TYPE_JPEG)
self.frame = Frame(image)
self.frame.Show()
self.SetTopWindow(self.frame)
return True
def main():
app = App()
app.MainLoop()
if __name__ == "__main__":
main()
Hope this helps.
R.
Offline
Thanks for the code - I think i understand it, but is it using wx? i wanted gtk but I guess its similar just a couple of different calls
I was hoping to be able to do it in glade but I guess I'll have to build it all from the command line... Unless you can make a custom control/display for glade? is it possible to embed code like that above into a glade container?
Offline
glade is a layout engine? for gtk
so yeh, you need pygtk.
in glade you can add a gtkimage widget and from pygtk load the file location directly into it with the set_from_file method
http://www.pygtk.org/docs/pygtk/class-gtkimage.html
Offline
Pages: 1