0
請幫我這個代碼。我想在框架中顯示的圖像:在wxpython中顯示圖像
import wx
import os
class frame(wx.Frame):
'''frame class that display an image'''
def __init__(self, image, parent=None, id=-1,
pos=wx.DefaultPosition, title='Hello, wxPyhton!'):
'''creat a frame instance and display image.'''
temp = image.ConvertToBitmap()
size = temp.GetWidth(), temp.GetHeight()
wx.Frame(parent, id, pos, title, size)
self.bmp = wx.StaticBitmap(parent=self, bitmap=temp)
class App(wx.App):
'''Application class.'''
def OnInit(self):
image = wx.Image('clem.jpg', wx.BITMAP_TYPE_JPEG)
self.frame = frame(image)
self.frame.Show()
return True
if __name__ == '__main__':
app = App()
app.MainLoop()
但我得到這個錯誤:
Traceback (most recent call last):
File "C:/PycharmProjects/WXPYHTON/hello.py", line 18, in OnInit
self.frame = frame(image)
File "C:/PycharmProjects/WXPYHTON/hello.py", line 11, in __init__
wx.Frame(parent, id, pos, title, size)
TypeError: Frame(): arguments did not match any overloaded call:
overload 1: too many arguments
overload 2: argument 3 has unexpected type 'Point'
OnInit returned false, exiting...
Process finished with exit code 1
請幫助這個代碼。我不知道我在哪裏弄錯了。
我已經改變了,但我仍然收到此錯誤
Traceback (most recent call last):
File "C:/PycharmProjects/WXPYHTON/hello.py", line 18, in OnInit
self.frame = frame(image)
File "C:/PycharmProjects/WXPYHTON/hello.py", line 12, in __init__
self.bmp = wx.StaticBitmap(parent=None, bitmap=temp)
TypeError: StaticBitmap(): arguments did not match any overloaded call:
overload 1: 'parent' is not a valid keyword argument
overload 2: 'bitmap' is not a valid keyword argument
OnInit returned false, exiting...
請我self.bmp,如果它是正確的。謝謝
請檢查我的代碼@Rolf of Saxony –
您的原始代碼讀取'self.bmp = wx.StaticBitmap(parent = self,bitmap = temp)'現在錯誤讀取'self.bmp = wx.StaticBitmap(parent = None ,bitmap = temp)'一個位圖應該有一個父窗口而不是'None'。回到使用'parent = self'。那些錯誤看起來像是來自pycharm,其中我什麼都不知道。 –