2016-08-14 82 views
0

下面是代碼一旦運行(解決)tkMessageBox崩潰Python應用程序

import Tkinter 
import tkMessageBox 

def created(): 
    tkMessageBox.showinfo('File Created!', 'Letter.html Created on Desktop') 

class simpleapp_tk(Tkinter.Tk): 
    def __init__(self,parent): 
     Tkinter.Tk.__init__(self,parent) 
     self.parent = parent 
     self.initialize() 

    def initialize(self): 
     self.grid() 

--- Everything Fine Here --- 

     self.B = Tkinter.Button(self, text = 'Create Document', command = self.OnButtonClick) 
     self.B.grid(column = 0, row = 6) 


    def OnButtonClick(self): 
     created() 


if __name__ == "__main__": 
    app = simpleapp_tk(None) 
    app.title('Receipt Form') 
    app.iconbitmap(os.getcwd() + '/M.tiff') 
    app.mainloop() 

我用py2app創建這個獨立的應用程序,但是當我運行它,並按下按鈕,它似乎崩潰。

我非常確定它是tkMessageBox引起的問題,但消息框在IDLE中工作得很好。

它也適用於我的Windows 10電腦與pyinstaller罰款。

編輯:問題似乎解決自身

回答

0

py2exe是py2app的Windows版本。

首先要建立我們需要一個安裝文件這樣的:

[setup.py]

from distutils.core import setup 
import py2exe      #in your case import py2app 
setup(console=['myFile.py']) 

使用蟒蛇setup.py py2exe運行此文件:

它會調用設置並告訴它我們想要一個控制檯應用程序,主入口點是「myFile.py」。

完成構建時,會創建兩個目錄。查看dist目錄並運行您的應用程序。

它工作得很好。

沒有錯誤

PS - 對您的圖標確保路徑是正確的

output screenshot here

+0

我已經有了setup.py和一切,但它是模塊tkMessageBox似乎崩潰的應用程序。一旦該按鈕self.B被按下,應用程序崩潰。 –

+0

它必須是一些構建問題。爲我工作得很好。 –

+0

MacOSX上的tkMessageBox與py2app與python 2.7? –