0

アプリの保存ボタンをクリックすると、正しく機能する保存ダイアログが開き、閉じようとするとすぐにクラッシュする 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()
4

1 に答える 1