python
1コード from tkinter import * 2HEIGHT = 500 3WIDTH = 800 4window = Tk() 5window.title('潜水艦ゲーム') 6c = Canvas(window, width=WIDTH, height=HEIGHT,bg='darkblue') 7c.pack() 8ship_id = c.create_polygon(5, 5, 5, 25, 30, 15, fill='red') 9ship_id2 = c.create_oval(0, 0, 30, 30, outline='red') 10ship_R = 15 11MID_X = WIDTH / 2 12MID_Y = HEIGHT / 2 13c.move(ship_id, MID_X, MID_Y) 14c.move(ship_id2, MID_X, MID_Y) 15SHIP_SPD = 10 16def move_ship(enent): 17 if event.keysym == 'Up': 18 c.move(ship_id, 10, -SHIP_SPD) 19 c.move(ship_id2, 10, -SHIP_SPD) 20 elif event.keysym== 'Down': 21 c.move(ship_id, 0, SHIP_SPD) 22 c.move(ship_id2, 0, SHIP_SPD) 23 elif event.keysym== 'Left': 24 c.move(ship_id, -SHIP_SPD, 0) 25 c.move(ship_id2, -SHIP_SPD, 0) 26 elif event.keysym== 'Right': 27 c.move(ship_id, SHIP_SPD, 0) 28 c.move(ship_id2, SHIP_SPD, 0) 29c.bind_all('<Key>', move_ship) 30
パイソンで船を動かすコードを書いています
上記のようにかいたのですが船が動きません
何が間違っているのでしょうか
インデントが潰れてコードが読めないので、質問文を編集して<code>ボタンを使いコードブロックで囲んでください(以下のようにしてもできます。)
```python
ここにコード(最後に改行が必要
```
エラー部分の情報も残しておいてください。
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\ayako\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:/Users/ayako/AppData/Local/Programs/Python/Python37/クイズ.py", line 17, in move_ship
if event.keysym == 'Up':
NameError: name 'event' is not definedとなりました
回答1件
あなたの回答
tips
プレビュー