语法无效 - 超级
Invalid Syntax - super
我正在为 python3 项目制作 GUI。我正在使用 wxpython。我在 VSCode.
中收到 "invalid syntax" 错误
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()
我不确定为什么会出现语法错误。抱歉新手问题。
首先,您在 super()
.
的调用末尾似乎有一个额外的括号
此外,在 super().__init__()
中,您在关键字参数之后传递位置参数,在 python 中不能这样做:
super(windowClass, self).__init__(parent, title=title, size = 200,300))
您需要在 parent
之后指定 300
或通过关键字传递它。
我猜,虽然那个 (200, 300) 应该是一个元组,或者一个列表来指定 window 大小,如果是这样的话,你需要把它括在括号中:
super(windowClass, self).__init__(parent, title=title, size=(200,300))
我正在为 python3 项目制作 GUI。我正在使用 wxpython。我在 VSCode.
中收到 "invalid syntax" 错误
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()
我不确定为什么会出现语法错误。抱歉新手问题。
首先,您在 super()
.
此外,在 super().__init__()
中,您在关键字参数之后传递位置参数,在 python 中不能这样做:
super(windowClass, self).__init__(parent, title=title, size = 200,300))
您需要在 parent
之后指定 300
或通过关键字传递它。
我猜,虽然那个 (200, 300) 应该是一个元组,或者一个列表来指定 window 大小,如果是这样的话,你需要把它括在括号中:
super(windowClass, self).__init__(parent, title=title, size=(200,300))