そこで、Tkinterを使用してテキスト入力を受け取り、そこからpygamesを実行してアニメーションを作成しようとしています。Pygamesを閉じるとエラーが発生します。
Pygamesの使用方法の簡略版:
def the_program():
if spot.get().strip() == "":
tkMessageBox.showerror("X", "Y")
else:
code = spot.get().strip()
pygame.init()
pygame.display.set_caption('X')
windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32)
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
Tkinterの実行:
root = Tk()
frame = Frame(root)
text = Label(frame, text='X')
spot = Entry(frame)
button = Button(frame, text = 'Ready?', command = the_program) "Starts Pygames"
frame.pack()
text.pack()
spot.pack()
button.pack()
root.mainloop()
Pygamesは正常に開き、正常に動作しますが、閉じると次のエラーが発生します。
Traceback (most recent call last):
File "C:\Python26\Practice\legit Battle Master.py", line 82, in <module>
root.mainloop()
File "C:\Python26\lib\lib-tk\Tkinter.py", line 1017, in mainloop
self.tk.mainloop(n)
File "C:\Python26\lib\lib-tk\Tkinter.py", line 1412, in __call__
raise SystemExit, msg
どうすればこれを回避できますか?「sys.exit()」を削除しようとしましたが、Pythonがクラッシュします。