请帮我这个代码。我想在框架中显示图像:
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,如果它是正确的。感谢
答案 0 :(得分:0)
您没有正确初始化框架,并且您使用关键字作为变量名称 变化:
wx.Frame(parent, id, pos, title, size)
要:
wx.Frame.__init__(self,parent,id,pos=pos,title=title,size=size)
它应该有用。