SyntaxError"没有可行的选择在输入' self'"

时间:2014-07-21 04:16:14

标签: python jython

我有一个包含以下代码的gui.py文件:

from javax.swing import JFrame, JPanel, Box, JComboBox, JSpinner, JButton, JLabel, SpinnerNumberModel, WindowConstants
from java.awt import BoxLayout, GridLayout

class SettingsWindow:

    def start( self ):
        selected = self.combobox.selectedIndex
        if selected >= 0:
            self.map = self.map_list[ selected ]
        self.games = self.spinner.getValue()

    def __init__( self, map_list ):
        frame = JFrame( "Settings" )
        frame.setSize( 200, 250 )
        frame.setLayout( BoxLayout() )
        panel = JPanel( GridLayout( 3, 1 )

        # Map Combobox
        self.map_list = map_list
        self.combobox = JComboBox( self.map_list )
        map_box = Box( BoxLayout.X_AXIS )
        map_box.add( JLabel( "Select map file:" ) )
        map_box.add( Box.createHorizontalStrut( 15 ) )
        map_box.add( self.combobox )
        panel.add( map_box )

        # Games Spinner
        self.spinner = JSpinner( SpinnerNumberModel( 1, 1, 25, 1 ) )
        games_box = Box( BoxLayout.X_AXIS )
        games_box.add( JLabel( "Number of games:" ) )
        map_box.add( Box.createHorizontalStrut( 15 ) )
        games_box.add( self.spinner )
        panel.add( games_box )

        # Start Button
        btn = JButton( "Start", actionPerformed = self.start )
        btn_box = Box( BoxLayout.X_AXIS )
        btn_box.add( btn )
        panel.add( btn_box )

        frame.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE )
        frame.setVisible( True )

    if __name__ == '__main__':
        SettingsWindow()

然后,在我的主文件中,我使用以下代码调用上面的类:

settings = gui.SettingsWindow( map_list )

我收到错误:

SyntaxError ( ("no viable alternative at input 'self'",   ('.../gui.py', 19, 8, '        self.map_list = map_list\n')) )

如果有人能看到我所缺少的东西,我会非常感谢你的帮助!

1 个答案:

答案 0 :(得分:26)

您忘记关闭上一行代码中的parens。