I have freezed a Tkinter-using GUI Python 3.4 app with cx_Freeze and when I tried to run it, I was presented the following error:
NameError: name 'font' is not defined.
When I remove all references to font from my code (i. e., if I don't set ttk Label fonts anywhere In the code), it works just fine and the exe runs nicely. I have checked the library.zip archive created by the freeze script and it does contain the font.pyc file in the tkinter directory. This is what my setup.py file looks like:
import cx_Freeze
import sys
import tkinter
base = None
if sys.platform == 'win32':
base = "Win32GUI"
executables = [cx_Freeze.Executable("rocnikovka.py", base=base)]
cx_Freeze.setup(
name = "Number evolution",
options = {"build_exe": {"packages":["tkinter", "tkinter.font"], "includes": ["tkinter", "tkinter.font"]}},
version = "0.01",
description = "Rocnikovka",
executables = executables
)
Any help is appreciated.
UPDATE: I have also tried making an executable out of the script with py2exe but ended up with the same result. Seems like a problem with tkinter rather than with cx_Freeze.
UPDATE #2: I import tkinter and ttk in the script like this:
from tkinter import *
from tkinter import ttk
I have a few fonts defined in the script, like this one:
font_title = font.Font(family = "Exo 2", size = 20, weight = "bold")
which I then use as the font parameter of ttk.Label objects.
This all works just fine when run as a script in IDLE.
Thanks to Arden, I was able to get it to work adding an explicit font sub-module import:
from tkinter import font
Works perfectly good now.