前提・実現したいこと
最近Pythonを始めたのですが、以下のプログラムでErrorが出て困っています
Errorの内容自体も理解していません。
対処法とできれば、このErrorの意味も教えてください。
発生している問題・エラーメッセージ
Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\PC_User\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__ return self.func(*args) File "C:\Users\PC_User\AppData\Local\Programs\Python\Python37-32\lib\turtle.py", line 675, in eventfun fun(x, y) TypeError: draw_line() takes 0 positional arguments but 2 were given
該当のソースコード
import turtle import sys import os # 出力ファイル dirname = os.path.dirname(__file__) path = os.path.join(dirname, "tpos.txt") my_turtle = turtle.Turtle() screen = turtle.Screen() screen.setup(800, 800) screen.title("テキストファイルの書き出し") my_turtle.pensize(3) my_turtle.shapesize(2) my_turtle.shape("turtle") # タートルの位置 pos = [] def up(): my_turtle.penup() def down(): my_turtle.pendown() def quit(): with open(path, mode="w", encoding="utf8") as f: for p in pos: f.write(f"{int(p[0])},{int(p[1])},{p[2]}\n") sys.exit() def draw_line(x, y): if my_turtle.isdown(): pos.append((x, y, "d")) else: pos.append((x, y, "u")) my_turtle.setheading(my_turtle.towards(x, y)) my_turtle.setpos(x, y) screen.listen() screen.onkey(up, "Up") screen.onkey(down, "Down") screen.onkey(quit, "q") screen.onscreenclick(draw_line) screen.mainloop()
試したこと
https://book.impress.co.jp/books/1117101089
内容としてはこのサイトの本をやっています。
samplefiles\Chapter6\samples6-3\twrite1.pyが該当のものです。
こちらの本のサンプルファイルを使うとうまくいくのですが、自作の方がなぜか上記のエラーとなります。
サンプルファイルをコピペしてもうまくいきます。
ディレクトリの問題かとも思いましたが、別ディレクトリに作っても自作はうまくいきません。
### 補足情報(FW/ツールのバージョンなど) 初歩的なミスかもしれませんが、ご回答よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/10/08 17:38