I have a tkinter program like the one below (for example) and want to create an executable file using module cx_freeze.
I am using Python33 and Windows7.

# Tk_circle2.py
# draw a circle with given center (x,y) and radius
# tkinter normally needs a specified square

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

def get_center(x1, y1, x2, y2):
    '''
    for a rectangle with ulc=(x1,y1) and lrc=(x2,y2)
    calculate the center (x,y)
    '''
    x = x1 + (x2 - x1)//2
    y = y1 + (y2 - y1)//2
    return x, y

def get_square(x, y, radius):
    '''
    given the center=(x,y) and radius
    calculate the square for the circle to fit into
    return x1, y1, x2, y2 of square's ulc=(x1,y1) and lrc=(x2,y2)
    '''
    x1 = x - radius
    y1 = y - radius
    x2 = x + radius
    y2 = y + radius
    return x1, y1, x2, y2

# create the basic window, let's call it 'root'
root = tk.Tk()

# create a canvas to draw on
cv = tk.Canvas(root, width=300, height=300, bg='white')
cv.grid()

# draw a circle with given center (x,y) and radius
x, y = 150, 120
radius = 65
# to draw a circle you need to get the ul and lr corner coordinates
# of a square that the circle will fit inside of
rect = get_square(x, y, radius)
# draw the cicle that fits into the rect/square
# default fill is canvas bg
#cv.create_oval(rect)
circle1 = cv.create_oval(rect, fill='red')
# optionally show the recangle the circle fits into
cv.create_rectangle(rect)

# testing ...
print(get_square(x, y, radius))  # (10, 10, 90, 90)
print(get_center(*rect))   # (50, 50)
# ul and lr box corners of square around circle
print(cv.coords(circle1))  # [10.0, 10.0, 90.0, 90.0]

# start the event loop
root.mainloop()

Can any body show me a setup code to do this?
I have not been successful.

Here is one way that I use frequently ...

""" tk_setup.py

Using cx_Freeze with Python33 to package a Tkinter GUI toolkit
program to an executable file (.exe in Windows OS).  Module
cx_Freeze also is available for Unix systems.

Put this setup program and your Tkinter program file into the same
directory.  Then run the setup script with the correct Python version.
You may have to change the filename in this setup script and also edit
name, version and description in setup() if you so desire.

A directory 'build' is created with a subdirectory 'exe.win32-3.3'
containing all the files needed for distribution including the
.exe file named after the Tkinter program file.

The total distribution has a size of about 14 MB

I used:
cx_Freeze-4.3.3.win32-py3.3.exe
from:
https://pypi.python.org/pypi?:action=display&name=cx_Freeze&version=4.3.3

tested with Python3.3.3
"""

import sys
from cx_Freeze import setup, Executable

# replaces commandline arg 'build'
sys.argv.append("build")  

# change the filename to your program file --->
filename = "tk_circle2.py"

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

setup(
    name = "Circle",
    version = "1.0",
    description = "cx_Freeze Tkinter script",
    executables = [Executable(filename, base=base)])

I used Windows 8.1

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.