![wxpython imageviewer wxpython imageviewer](https://raw.githubusercontent.com/PySimpleGUI/PySimpleGUI/master/images/for_readme/First_GUI2.jpg)
(self.sizer, 0, wx.ALL, 5)ĭialog = wx.FileDialog(None, "Choose a file", Self.mainSizer = wx.BoxSizer(wx.VERTICAL) Self.photoTxt = wx.TextCtrl(self.panel, size=(200,-1))īrowseBtn = wx.Button(self.panel, label='Browse')īrowseBtn.Bind(wx.EVT_BUTTON, self.onBrowse) InstructLbl = wx.StaticText(self.panel, label=instructions) Self.imageCtrl = wx.StaticBitmap(self.panel, wx.ID_ANY, ame = wx.Frame(None, title='Photo Control') That's enough for the introductions, let's look at the code:ĭef _init_(self, redirect=False, filename=None):
![wxpython imageviewer wxpython imageviewer](https://user-images.githubusercontent.com/6867503/121929417-90ab0100-cd17-11eb-9234-7134b736ef5c.png)
For that, we'll use a tip I received from the illustrious Andrea Gavana (creator of the AGW library). Finally, we need a way to scale the image down if it's too large for either our resolution or our application. In this example, we want a placeholder for the image, so we'll use wx.EmptyImage for that. One of the simplest ways to display an image in wxPython is to use the wx.StaticBitmap to do your dirty work. Since this is a fairly popular topic, I thought it would be wise to let you, dear reader, in on the secret. There are lots of different ways to do this, but I had a pre-made solution that I'd cobbled together a couple of years ago for work.
WXPYTHON IMAGEVIEWER HOW TO
Self.bitmap = ()ĭc = wx.BufferedDC(wx.ClientDC(self), self.The other day, I was chatting with some wxPython newbies on the wxPython IRC channel and one of them wanted to know how to display images in wx. # Finally blit buffer to show the final imageĭc = wx.BufferedDC(wx.ClientDC(self), self.bitmap)ĭc = wx.BufferedPaintDC(self, self.bitmap) # restores the former content to the window. # When the mouse is released we reset the overlay and it Rect = wx.Rect(self._startPos, evt.Position)ĭc = wx.GCDC(dc) # <- necessary for transparency? # Comment out the next line if you don't want to draw on a bitmap Self.image = wx.Image("phoenix-fire-md.png") Self.Bind(wx.EVT_MOTION, self.OnMouseMove) Self.Bind(wx.EVT_LEFT_DCLICK, lambda v: self.Draw()) Self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
WXPYTHON IMAGEVIEWER CODE
If the posted code was not only minimum but also runnable, I think you will get more advice.Īnyway, I made a small code, hope this would be a help for you to start up. I tried to run your code but couldn’t because of many undefined name errors. So i asume that’s someting related to the dcOverlay.Clear() call, because when i comment it out it doesnt reset the image but i need it to clear the rectangles that show when i’m moving the mouse Te problem is that whenever I start the tagging process, when i start moving the mouse the picture resets to the first tagged picture, but the finished rectangle draws properly over the respective image. X_1, y_1 = e.GetLogicalPosition(dc).Get()ĭc.DrawRectangle(x_0, y_0, width, height) MainBox.Add(appBox,proportion=1,flag=wx.EXPAND)ĭcOverlay = wx.DCOverlay(self.overlay,dc) #Combine app and fileExplorer into main sizerįlag=wx.EXPAND|wx.LEFT|wx.RIGHT|wx.BOTTOM, #Add Viewer + Tagger box and Buttom box to make main appĪppBox.Add(innerBox,proportion=1,flag=wx.EXPAND)ĪppBox.Add(buttonBox,flag=wx.EXPAND|wx.TOP|wx.BOTTOM,border = 20) InnerBox.Add(tagBox,proportion=1,flag=wx.EXPAND) InnerBox.Add(imagePanel,proportion=1,flag=wx.EXPAND|wx.TOP,border = 20) #Combine image viewer and tag lister into the inner box ImageBox.Add(bitmap,proportion=1,flag = wx.ALL|wx.EXPAND,border = 5)
![wxpython imageviewer wxpython imageviewer](http://thedorkside.com/wp-content/uploads/2012/12/slideshow_viewer_slide_order.jpg)
Image = image.Scale(imageSize.GetWidth() - 10,īitmap = wx.StaticBitmap(imagePanel,id=BITMAP,bitmap=wx.Bitmap(image)) ImagePanel.SetBackgroundColour('#000000') ImagePanel = wx.Panel(panel, size=wx.Size(550,600)) Super(TaggerUI,self)._init_(*args,**kwargs)įont = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT) My main window looks a like this (omiting some code irrelevant to the topic): class TaggerUI(wx.Frame): Here’s the deal, i’m working on a Image tagger for an AI model training.