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