1
버튼을 클릭 할 때 프로그램 시작시 패널에 놓인 64x64 이미지가 더 큰 320x224 이미지로 바뀌는 것처럼 이미지 패널을 폼에 배치하려고합니다. 픽셀 크기는 그다지 중요하지 않습니다. 그들은 다른 크기가되고 있습니다. 나는 거의 그것을 가지고있다 - 지금 이미지가로드되고 실제로 버튼이 클릭되었을 때 두 번째 이미지가 올려진다. 불행히도 그것은 전체 이미지가 아닌 두 번째 이미지의 왼쪽 상단 64x64이다.wxPython wx.Panel의 크기를 변경 하시겠습니까?
전체 이미지를 볼 수 있도록 패널의 크기를 조정할 수 있어야합니다.
가 (. 그것은 onOpenFileDialog으로 결국은 콤보 경로에서 이미지를 따기있을거야라고)#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 방법을 편집 할 수있는 방법은 이미지 크기를 발견 같은 : 같이 여기 내 코드는 먼저, 초기 폼 요소 생성시 self.imageCtrl 줄 에서처럼? 나는 그것을하는 방법을 찾을 수 없습니다.
이 감사에서
self.v_sizer.Fit(self)
를 호출 시도, 그게있어! :) – user241308들으니 다행 :) – volting