7
Ho un file gui.py contenente il codice seguente:SyntaxError "nessuna alternativa valida sull'ingresso 'sé'"
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()
Poi, nel mio file principale, che io chiamo la classe superiore con questo codice:
settings = gui.SettingsWindow(map_list)
E ottengo l'errore:
SyntaxError (("no viable alternative at input 'self'", ('.../gui.py', 19, 8, ' self.map_list = map_list\n')))
Se chiunque può vedere ciò che mi manca, sarei davvero grato per l'aiuto!