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.