wxpython +opencv打開(kāi)圖片
import wx
import os
import CV2
class picLog(wx.Frame):
? ? def __init__(self):
? ? ? ? wx.Frame.__init__(self,None,title='picLog',size=(640,480))
? ? ? ? self.SelBtn = wx.Button(self,label='>>',pos=(305,5),size=(80,25))
? ? ? ? self.SelBtn.Bind(wx.EVT_BUTTON,self.OnOpenFile)
? ? ? ? self.OkBtn = wx.Button(self,label='OK',pos=(405,5),size=(80,25))
? ? ? ? self.OkBtn.Bind(wx.EVT_BUTTON,self.Onpic)
? ? ? ? self.FileName = wx.TextCtrl(self,pos=(5,5),size=(230,25))
? ? ? ? self.panel = wx.Panel(self,pos=(30,30),size=(1320,960))
? ??
? ? def OnOpenFile(self,event):
? ? ? ? wildcard = 'All files(*.*)|*.*'
? ? ? ? dialog = wx.FileDialog(None,'select',os.getcwd(),'',wildcard,wx.FD_OPEN) ?#####這個(gè)部分新舊版本有變化
? ? ? ? if dialog.ShowModal() == wx.ID_OK:
? ? ? ? ? ? self.FileName.SetValue(dialog.GetPath())
? ? ? ? ? ? dialog.Destroy
? ? ? ??
? ??
? ? def Onpic(self,event):
? ? ? ? panel=wx.Panel(self,pos=(30,30),size=(1320,960))
? ? ? ? img = CV2.imread(self.FileName.GetValue())
? ? ? ? CV2.imshow('image',img)
? ? ? ? ?
if __name__=='__main__':
? ? app = wx.App()
? ? SiteFrame = picLog()
? ? SiteFrame.Show()
? ? app.MainLoop()