0

Please help me with this code. I want to display image in the frame :

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()

But i got this error:

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

please help this code. i don't know where i'm getting it wrong.

I've changed it but i'm still getting this error

 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...

please check my self.bmp, if it is correct. Thanks

1 Answer 1

1

You are not initialising the frame properly and you are using keywords as variable names.
Change:

wx.Frame(parent, id, pos, title, size)

To:

wx.Frame.__init__(self,parent,id,pos=pos,title=title,size=size)

and it should work.

Sign up to request clarification or add additional context in comments.

1 Comment

your original code read self.bmp = wx.StaticBitmap(parent=self, bitmap=temp) now the error reads self.bmp = wx.StaticBitmap(parent=None, bitmap=temp) A bitmap should have a parent window not None. Go back to using parent=self. Those errors look like they are coming from pycharm, of which I know nothing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.