ページアップキーが押されたときにPythonのカメのペンサイズを増加させるプログラムにします。TypeError:+ =: 'method'と 'int'のためのサポートされていないオペランドタイプ
#!/usr/bin/env python3
import turtle
wn=turtle.Screen()
wn.title('Control using first letter of desired action')
py=turtle.Turtle()
py.color('blue')
size=1
def front():
py.fd(90)
def back():
py.bk(90)
def right():
py.rt(45)
def left():
py.lt(45)
def increasize():
global size
while size>=1 and size<=20:
py.pensize+=1
def decreasize():
global size
while size>=1 and size<=20:
py.pensize-=1
wn.onkey(front,'w')
wn.onkey(back,'s')
wn.onkey(right,'d')
wn.onkey(left,'a')
wn.onkey(increasize,'Prior')
wn.onkey(decreasize,'Next')
wn.listen()
wn.mainloop()
しかし、それはエラーを与える: 私は次のことを試してみました。完全なトレースバック:
Exception in Tkinter callback
Traceback (most recent call last):
File "c:\program files\python3\lib\tkinter\__init__.py", line 1549, in __call__
return self.func(*args)
File "c:\program files\python3\lib\turtle.py", line 686, in eventfun
fun()
File "D:\Python\draw_straight_key.py", line 19, in increasize
py.pensize+=1
TypeError: unsupported operand type(s) for +=: 'method' and 'int'
Exception in Tkinter callback
Traceback (most recent call last):
File "c:\program files\python3\lib\tkinter\__init__.py", line 1549, in __call__
return self.func(*args)
File "c:\program files\python3\lib\turtle.py", line 686, in eventfun
fun()
File "D:\Python\draw_straight_key.py", line 23, in decreasize
py.pensize-=1
TypeError: unsupported operand type(s) for -=: 'method' and 'int'
質問の本文にコードを入力してください。 – MattDMo
エラーまたはトレースバックの**フルテキスト**も投稿してください。 – MattDMo
pensizeはメソッドであり、変数ではありません。 [docs](https://docs.python.org/2/library/turtle.html#turtle.pensize)を見て、自分で修正してください。 – Natecat