所以我想用Tkinter來接收文本輸入,然後從那裏運行pygames來做動畫。當我關閉Pygames時,我得到一個錯誤。如何在不關閉tkinter的情況下關閉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崩潰。
選擇所有的行源代碼,然後按CTRL + K創造更好的語法高亮和代碼格式化,請:) – Constantinius 2011-05-12 20:15:21