|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import wx
- import os
- 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) #####
- #这个部分新旧版本有变化
- 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))
- img3 = wx.Image(self.FileName.GetValue(),wx.BITMAP_TYPE_ANY).ConvertToBitmap()
- show3 = wx.StaticBitmap(self, -1, img3,pos=(20, 0),size=(1080,600))
-
- if __name__ == '__main__':
- app = wx.App()
- SiteFrame = picLog(parent=None,id=-1)
- SiteFrame.Show()
- app.MainLoop()
复制代码
想要wxpython创建一个界面,可以打开选择文件,自己随意用鼠标点击选择。运行这个代码,出来的界面没有按钮和动态文本。请问应该怎么办
__init__ 是双下划线的
- import wx
- import os
- class picLog(wx.Frame):
- def __init__(self):
- wx.Frame.__init__(self, None, title='picLog', size=(640, 480))
- self.panel = wx.Panel(self)
- self.SelBtn = wx.Button(self.panel, label='>>', pos=(305, 5), size=(80, 25))
- self.SelBtn.Bind(wx.EVT_BUTTON, self.OnOpenFile)
- self.OkBtn = wx.Button(self.panel, label='OK', pos=(405, 5), size=(80, 25))
- self.OkBtn.Bind(wx.EVT_BUTTON, self.Onpic)
- self.FileName = wx.TextCtrl(self.panel, pos=(5, 5), size=(230, 25))
- def OnOpenFile(self, event):
- wildcard = 'All files(*.*)|*.*'
- dialog = wx.FileDialog(None, 'select', os.getcwd(), '', wildcard, wx.FD_OPEN) #####
- # 这个部分新旧版本有变化
- 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))
- img3 = wx.Image(self.FileName.GetValue(), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
- show3 = wx.StaticBitmap(self, -1, img3, pos=(20, 0), size=(1080, 600))
- if __name__ == '__main__':
- app = wx.App()
- SiteFrame = picLog()
- SiteFrame.Show()
- app.MainLoop()
复制代码
|
|