[Tutor] Really basic won't run error
dn
PyTutor at DancesWithMice.info
Sun Jul 4 05:16:02 EDT 2021
On 04/07/2021 19.17, Phil wrote:
> I've been working on this idea for most of the day and have finally
> reduced the problem to a wxPython demo example but it won't run. No
> doubt the reason is obvious but I cannot see it.
>
> import wx
>
> class ImagePanel(wx.Panel):
> def __init__(self, parent):
> wx.Panel.__init__(self, parent, -1)#None, title="Bitmap test")
>
> wx.StaticText(self, -1, "This is a wx.StaticBitmap.", (45, 15))
>
> bmp = 'test.jpg'.GetBitmap()
> #mask = wx.Mask(bmp, wx.BLUE)
> #bmp.SetMask(mask)
> #StaticBitmap(self, -1, bmp, (80, 50), (bmp.GetWidth(),
> bmp.GetHeight()))
>
> StaticBitmap(self, -1, bmp, (80, 150))
>
> if __name__ == "__main__":
> app = wx.App()
> frame = ImagePanel().Show()
> app.MainLoop()
>
> Traceback (most recent call last):
> File "/usr/lib/python3.8/idlelib/run.py", line 559, in runcode
> exec(code, self.locals)
> File "/home/phil/Python/wxpython_bitmap.py", line 38, in <module>
> frame = MyFrame().Show()
> TypeError: __init__() missing 1 required positional argument: 'parent'
Reading the err.msgs we are first pointed to "line 38" which attempts to
first "instantiate" and then "Show" an "ImagePanel", with the comment
that a "positional argument" is missing (omitted).
Previously in the code, class ImagePanel is defined. Its __init__()
declares a "parent" parameter. This is missing from line 38.
It has been a while since I played with wxPython. Should the "app"
object, instantiated on line 37, be provided as an argument to ImagePanel?
--
Regards,
=dn
More information about the Tutor
mailing list