繁体   English   中英

调整wxPython wx.Panel的大小?

[英]Resizing a wxPython wx.Panel?

我试图将图像面板放置在窗体上,以便当单击按钮时,将程序启动时放置在面板上的64x64图像替换为更大的320x224图像-像素大小并不是那么重要大小不同。 我已经知道了-现在两个图像都已加载,并且确实确实在单击按钮时将第二个图像调高了-不幸的是,它是第二个图像的左上方64x64,而不是整个图像。

必须能够调整面板的大小,以便可以查看整个图像,确定吗? 这是我的代码:

#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,因为最终它将从组合框路径中选择图像。)

我如何编辑onOpenFileDialog方法,例如它首先找到图像大小,就像在初始表单元素创建中的self.imageCtrl行中那样? 我找不到解决办法。

尝试在onOpenFileDialog()方法末尾调用self.v_sizer.Fit(self)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM