3
私はPythonでカメを使って簡単なボタンプログラムを作成しました。 これはたぶん非常にうんざりですが、IDLEでは完全に機能します。しかし、IDLEなしでロードしようとすると、2つのボタンを描画してからプログラムを終了します。私は原因を見つけることに成功せずにコードを見てきました。IDLEでPython turtleプログラムが動作しない
def main():
onscreenclick(Button.clicked,1)
main()
しかし、私は完全にわからない:私は問題は(最後の数行)だと思うのはここ
です。ちょうどその場合の完全なプログラムです。
from turtle import *
bgcolor('skyblue')
penup()
left(90)
speed(0)
hideturtle()
buttonlist = []
class Button:
x_click = 0
y_click = 0
def __init__(self, x, y, size, color, text, fontsize, fixvalue):
self.x = x
self.y = y
self.size = size
self.color = color
self.text = text
self.fontsize = fontsize
self.fixvalue = fixvalue
def showButton(self):
goto(self.x , self.y)
pendown()
fillcolor(self.color)
begin_fill()
for i in range(4):
forward(self.size)
right(90)
end_fill()
penup()
goto((self.x+self.size/2),self.y+self.fixvalue)
right(90)
write(self.text, move=False, align="center", font=("Arial", self.fontsize, "normal"))
left(90)
def hideButton(self):
goto(self.x, self.y)
fillcolor('skyblue')
pencolor('skyblue')
pendown()
begin_fill()
for i in range(4):
forward(self.size)
right(90)
end_fill()
penup()
pencolor('black')
def checkClick(self):
if self.x < Button.x_click:
if Button.x_click < (self.x+self.size):
if self.y < Button.y_click:
if Button.y_click < (self.y+self.size):
return 1
def clicked(x, y):
Button.x_click = x
Button.y_click = y
if home_1.checkClick() == 1:
home_1.hideButton()
if home_2.checkClick() == 1:
home_2.hideButton()
home_1 = Button(10,10,100,'red','←',45,20)
home_2 = Button(-50,-50,50,'blue','Hello!',10,15)
Button.showButton(home_1)
Button.showButton(home_2)
def main():
onscreenclick(Button.clicked,1)
main()
解決策があることを願っています。
乾杯。
いくつかのWebサービスにリンクするのではなく、コードブロックを使用してコードを追加してください[MCVE](https://stackoverflow.com/help/mcve) – albert
私は非常にあなたを停止することをお勧めします'turtle import * 'を歌い、代わりに' turtle.penup()'などを使って 'turtle import 'を実行するだけです。同じことをどこでも何度も何度も書くのは馬鹿だと感じるかもしれませんが、あなたの将来の自己あなたに感謝します。このような短い名前をたくさんインポートすると、本当にすばやく混乱するでしょう。 –