2013-08-21 89 views
2

我使用這個,當我開始Python腳本蟒蛇3.2 Tkinter的圖標

root.wm_iconbitmap('icon.ico') 

但其工作正常cx_freeze編譯腳本並試圖執行編譯後的文件,我得到以下錯誤消息後

File "D:\Programme\Python\Lib\tkinter\__init__.py", line 1553, in wm_iconbitmap 
return self.tk.call('wm', 'iconbitmap', self._w, bitmap) 
_tkinter.TclError: bitmap "icon.ico" not defined 

因此無法找到圖標文件。 如何配置我的setup.py以包含圖標文件?

+0

可能重複[如何使用cx \ _freeze時捆綁其他文件?](http://stackoverflow.com/questions/2553886/how-can-i-bundle-other-files-when-using-cx -freeze) – Brionius

+0

請參閱文檔中的[使用數據文件](http://cx-freeze.readthedocs.org/en/latest/faq.html#using-data-files)。 –

回答

3

我不知道你是否已經解決了這個問題(鑑於這個問題有多大),但我有與你完全相同的問題,並感謝你的問題,它實際上解決了我的問題。

爲了包括你在叫includefilessetup.py腳本創建一個變量,然後在setup(代碼包括:options你的圖標文件(或你的Python程序籲請任何其他文件)。

以下是我用來做這件事的setup.py腳本。

import sys 
from cx_Freeze import setup, Executable 

base = None 
if (sys.platform == "win32"): 
    base = "Win32GUI" 

exe = Executable(
     script = "Binary to Decimal Converter.py", 
     icon = "python-xxl.ico", 
     targetName = "Binary to Decimal Converter.exe", 
     base = base 
     ) 
includefiles = ["python-xxl.ico"] 

setup(
    name = "Binary to Decimal Converter", 
    version = "0.1", 
    description = "Converts Binary values to Decimal values", 
    author = "Neeraj Morar", 
    options = {'build_exe': {'include_files':includefiles}}, 
    executables = [exe] 
) 

正如你所看到的,includefiles包括我的圖標文件名的(我要提醒你在同一個目錄下的文件作爲Python腳本)。然後,在我的setup(代碼options = {'build_exe': {'include_files':includefiles}}

'include_files'調用我創建的includefiles變量。基本上,你需要做的只是做與我一樣的事情,而不是將我的圖標文件名放在你的圖標文件名中;即includefiles = ["icon.ico"]