7
"girdi 'self' de geçerli hiçbir alternatif": benim ana dosyada,SyntaxError Aşağıdaki kodu içeren bir gui.py dosyasına sahip
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()
Sonra ben bu kodla yukarıdaki sınıf çağrı:
settings = gui.SettingsWindow(map_list)
Ve hatayı alıyorum:
SyntaxError (("no viable alternative at input 'self'", ('.../gui.py', 19, 8, ' self.map_list = map_list\n')))
kimse ben eksik görebiliyorsanız, yardım için minnettar olurdum!