每当我单击我的应用程序上的保存按钮时,它都会打开一个正常工作的保存对话框和一个 tkinter 窗口,一旦我尝试关闭它就会崩溃。这是我的代码,它以某种方式生成随机窗口:
import tkFileDialog,pygame
pygame.init()
screen = pygame.display.set_mode((640,360))
pygame.display.set_caption("Idea Processor")
# code is cut here
try:
ideasetupfonts = pygame.font.SysFont("Ubuntu", 36, False, False)
except:
ideasetupfonts = pygame.font.SysFont("Arial", 36, False, False)
# TextNameToBlit = ideasetupfonts.render(" TEXT HERE ",1,(0,0,0))
Potato = True
ShowToolbar = True
newSaveFile = {"Hello World":(50,50)}
def SaveFile():
filename = tkFileDialog.asksaveasfilename(**{"title":"Save Idea...","defaultextension":".txt","filetypes":[("text files", ".txt")],})
if filename:
saveFile = open(filename, 'w')
print >>saveFile,newSaveFile
saveFile.close()
while Potato:
for event in pygame.event.get():
if event.type == pygame.QUIT:
Potato = False
screen.fill(white)
# and here
mousex,mousey = pygame.mouse.get_pos()
# SaveFile button
if mousex>=0 and mousex<=32 and mousey>=0 and mousey<=32 and pygame.mouse.get_pressed() == (True, False, False) and ShowToolbar:
SaveFile()
# and here
pygame.display.flip()
pygame.quit()