my main file:
from tkinter import *
scr=Tk()
def spc():
print('')
add='false'
minus='false'
multiply='false'
divide='false'
first_digit=[]
second_digit=[]
scr.title('Calculator')
scr.iconbitmap('icon.ico')
entry=Entry(scr, width=60, borderwidth=3)
entry.grid(row=0, column=0, columnspan=5, padx=10,pady=15)
def write(number):
current=entry.get()
entry.delete(0, END)
entry.insert(0,current + str(number))
def clear_command():
global first_digit, second_digit
entry.delete(0, END)
first_digit=[]
second_digit=[]
everything_f()
def everything_f():
global add, minus, multiply, divide
add='false'
minus='false'
multiply='false'
divide='false'
#-------------operations funcs-------------
def add_command():
global add, minus, multiply, divide
add='true'
minus='false'
multiply='false'
divide='false'
now=entry.get()
first_digit.append(float(now))
entry.delete(0, END)
def minus_command():
global add, minus, multiply, divide
add='false'
minus='true'
multiply='false'
divide='false'
now=entry.get()
first_digit.append(float(now))
entry.delete(0, END)
def divide_command():
global add, minus, multiply, divide
add='false'
minus='false'
multiply='false'
divide='true'
now=entry.get()
first_digit.append(float(now))
entry.delete(0, END)
def multiply_command():
global add, minus, multiply, divide
add='false'
minus='false'
multiply='true'
divide='false'
now=entry.get()
first_digit.append(float(now))
entry.delete(0, END)
def equal_command():
global first_digit, second_digit
now=entry.get()
second_digit.append(float(now))
entry.delete(0,END)
if add=='true':
entry.insert(0,first_digit[0]+second_digit[0])
elif minus=='true':
entry.insert(0,first_digit[0]-second_digit[0])
elif divide=='true':
entry.insert(0,first_digit[0]/second_digit[0])
elif multiply=='true':
entry.insert(0,first_digit[0]*second_digit[0])
first_digit=[]
second_digit=[]
everything_f()
#----------finish funcs-------------
button_0=Button(scr, text='0', padx=40, pady=20, command=lambda: write(0))
button_1=Button(scr, text='1', padx=40, pady=20, command=lambda: write(1))
button_2=Button(scr, text='2', padx=40, pady=20, command=lambda: write(2))
button_3=Button(scr, text='3', padx=40, pady=20, command=lambda: write(3))
button_4=Button(scr, text='4', padx=40, pady=20, command=lambda: write(4))
button_5=Button(scr, text='5', padx=40, pady=20, command=lambda: write(5))
button_6=Button(scr, text='6', padx=40, pady=20, command=lambda: write(6))
button_7=Button(scr, text='7', padx=40, pady=20, command=lambda: write(7))
button_8=Button(scr, text='8', padx=40, pady=20, command=lambda: write(8))
button_9=Button(scr, text='9', padx=40, pady=20, command=lambda: write(9))
button_plus=Button(scr, text='+', padx=39, pady=20, command=add_command)
button_minus=Button(scr, text='-', padx=40, pady=20, command=minus_command)
button_equal=Button(scr, text='=', padx=90, pady=20, command=equal_command)
button_multiply=Button(scr, text='x', padx=39, pady=20, command=multiply_command)
button_divide=Button(scr, text='÷', padx=39, pady=20, command=divide_command)
button_clear=Button(scr, text='Clear', padx=90, pady=20, command=clear_command)
button_1.grid(row=3,column=1)
button_2.grid(row=3,column=2)
button_3.grid(row=3,column=3)
button_4.grid(row=2,column=1)
button_5.grid(row=2,column=2)
button_6.grid(row=2,column=3)
button_7.grid(row=1,column=1)
button_8.grid(row=1,column=2)
button_9.grid(row=1,column=3)
button_0.grid(row=4,column=2)
button_plus.grid(row=3,column=4)
button_minus.grid(row=4,column=4)
button_multiply.grid(row=1,column=4)
button_divide.grid(row=2,column=4)
button_equal.grid(row=5,column=3, columnspan=2)
button_clear.grid(row=5,column=1, columnspan=2)
my set up file:
import cx_Freeze
from cx_Freeze import setup, Executable
import sys
import tkinter
base=None
if sys.platform == 'win32':
base = 'Win32GUI'
executables=[cx_Freeze.Executable("tkinter_calc.py", base=base, icon="icon.ico")]
cx_Freeze.setup(
name="Calculator",
options={"build_exe":{"packages":["tkinter"], "include_files":["icon.ico"]}},
version="0.01",
executables=executables
)
I tried converting a calculator made with python and tkinter to an exe with cx_Freeze,
but when the app is build and ready, when I try to open it appears on the screen for less than a second and then disappears.
Please help.