WxPython Image Viewer to Display Bitmaps/PNG/JPG Images in Frames Panels Using Image Class GUI Desktop App Full Project For Beginners

WxPython Image Viewer to Display Bitmaps/PNG/JPG Images in Frames Panels Using Image Class GUI Desktop App Full Project For Beginners

 

Welcome folks today in this blog post we will be building a image viewer in wxpython and displaying bitmap/png/jpg images inside frames panels using frame and image class. All the full source code of the application is given below.

 

 

Get Started

 

 

In order to get started you need to install the below library using the pip command as shown below

 

pip install wxpython

 

After installing this library you need to make an app.py file and copy paste the following code

 

app.py

 

#!/usr/bin/env python

"""Hello, wxPython! program."""

#wxPython is a cross-platform GUI toolkit for the Python programming language
import wx

class Frame(wx.Frame):
    """Frame class that displays an image."""

    def __init__(self, image, parent=None, id=-1,
                 pos=wx.DefaultPosition, title='Hello, wxPython!'):
        """Create a Frame instance and display 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)
        self.SetClientSize(size)

class App(wx.App):
    """Application class."""

    def OnInit(self):
        image = wx.Image('wxPython.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()

 

See also  Python 3 Tkinter Script to Get Live Stock Market Price of Company Using Yahoo Finance API Full Project For Beginners

 

So as you can see in the above figure we are using the frames and images class and passing the path of the image and then showing it inside the image viewer as shown below

 

If you execute the above python script by typing the below command

 

python app.py

 

 

Leave a Reply