1
我试图放置一个窗体上的图像面板,当点击一个按钮时,在程序启动时放在面板上的64x64图像将被替换为更大的320x224图像 - 像素尺寸并不那么重要他们是不同的大小。我几乎得到了它 - 现在图像都加载,它确实把第二个按钮点击时 - 不幸的是它是第二个图像的左上64x64,而不是整个事情。调整wxPython wx.Panel的大小?
必须可以调整面板的大小,以便可以查看整个图像吗?这里是我的代码是:
#First we create our form elements. This app has a label on top of a button, both below a panel with an image on it, so we create a sizer and the elements
self.v_sizer = wx.BoxSizer(wx.VERTICAL)
self.imagePanel = wx.Panel(self, -1)
self.FileDescriptionText = wx.StaticText(self, label="No file loaded")
self.openFileDialog = wx.Button(self, label="Load a file", size=(320,40))
#Bind the button click to our press function
self.openFileDialog.Bind(wx.EVT_BUTTON, self.onOpenFileDialog)
#That done, we need to construct the form. First, put the panel, button and label in the vertical sizer...
self.v_sizer.Add(self.imagePanel, 0, flag=wx.ALIGN_CENTER)
self.v_sizer.Add(self.openFileDialog, 0, flag=wx.ALIGN_CENTER)
self.v_sizer.Add(self.ROMDescriptionText, 0, flag=wx.ALIGN_CENTER)
#then assign an image for the panel to have by default, and apply it
self.imageToLoad = wx.Image("imgs/none_loaded.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
self.imageCtrl = wx.StaticBitmap(self.imagePanel, -1, self.imageToLoad, (0, 0), (self.imageToLoad.GetWidth(), self.imageToLoad.GetHeight()))
#Set the sizer to be owned by the window
self.SetSizer(self.v_sizer)
#Set the current window size to the size of the sizer
self.v_sizer.Fit(self)
#Set the Minimum size of the window to the current size of the sizer
self.SetMinSize(self.v_sizer.GetMinSize())
def onOpenFileDialog(self, event):
img = wx.Image("imgs/title.png", wx.BITMAP_TYPE_ANY)
self.imageCtrl.SetBitmap(wx.BitmapFromImage(img))
self.imagePanel.Refresh()
(这就是所谓的onOpenFileDialog因为它最终会从ComboBox路径选择图像)
我如何可以编辑onOpenFileDialog方法,如发现图像尺寸首先,像它在初始表单元素创建中的self.imageCtrl行一样?我找不到一种方法。
谢谢你打电话
self.v_sizer.Fit(self)
,这是得到了它! :) – user241308 2010-08-14 19:07:16很高兴听到:) – volting 2010-08-14 19:09:43