Search code examples
python-3.xwxpython

Invalid Syntax - super


I am making a GUI for a python3 project. I am using wxpython. I recieve a "invalid syntax" error in VSCode.


import shutil
import os
import distutils
from distutils import dir_util
from __future__ import print_function
import datetime
import wx

class windowClass(wx.Frame):

    def __init__(self, parent, title):
        super(windowClass, self).__init__(parent, title=title, size = 200,300))

        self.Show()

app = wx.App()
windowClass(None, title='Window Title')
app.MainLoop()

I am not sure why it is having a syntax error. Sorry for the newbie question.


Solution

  • First thing, you seem to have an extra parenthesis at the end of your call to super().

    Also, in super().__init__() you are passing a positional argument after a keyword argument, you can't do that in python:

    super(windowClass, self).__init__(parent, title=title, size = 200,300))
    

    You need to either specify 300 after parent or pass it with a keyword too.

    I am guessing, though that (200, 300) should be a tuple, or a list to specify a window size, if that's the case, you need to wrap it in parentheses:

    super(windowClass, self).__init__(parent, title=title, size=(200,300))