Program closing immediately after opening (Post compiled)
I'm starting to study Tkinter and compilation, and I have a basic notion of Python, and I'm having some problems. Here is an example of a basic program that, after compiling, the executable just quickly opens a cmd and closes, without any other type of response, I have tried to use while True before the code, but it did not take effect.It must be something quite beast, but it is a legitimate doubt.
import tkinter as tk
from tkinter import *
import random
#####################################
abc='abcdefghijklmnopqrstuvwxyz'
rot=3
def cifrar(message):
m=''
n=0
for c in message:
c_index = abc.index(c)
if c_index<23:
m+=abc[c_index+rot]
elif c_index==23:
m+='a'
elif c_index==24:
m+='b'
elif c_index==25:
m+='c'
else:
m+=c
return m
def decifrar(message):
m=''
for d in message:
d_index=abc.index(d)
if d_index>=3:
m+=abc[d_index-rot]
elif d_index==0:
m+='x'
elif d_index==1:
m+='y'
elif d_index==2:
m+='z'
else:
m+=d_index
return m
#####################################
janela=tk.Tk()
janela.title('Convertor da Cifra de César')
def bt_click():
lb2['text']=str(cifrar(ed.get()))
janela['bg']='red'
########
cores=['blue','green','red','black']
######
def bt_click2():
lb2['text']=str(decifrar(ed.get()))
#
def changec():
janela['bg']=str(cores[random.randint(0,3)])
#
ed=Entry(janela, width='47')
ed.place(x=50,y=150)
#
lb=Label(janela, text='Convertor da Cifra de César')
lb.place(x=50,y=40)
lb.config(font=('Comic_Sans', 14))
#
lb2=Label(janela,text='', width='40')
lb2.place(x=50,y=180)
#
bt=Button(janela,text='Cifrar',command=bt_click, width=15)
bt.place(x=50,y=250)
#
bt2=Button(janela,text='Decifrar', width='15',command=bt_click2)
bt2.place(x=180,y=250)
#
bt3=Button(janela,text='Mudar cor de fundo',command=changec)
bt3.place(x=285,y=281)
#
janela.geometry(('400x300+320+140'))
janela.mainloop()
File code setup.py:
from cx_Freeze import setup, Executable
import os
import cx_Freeze
os.environ['TCL_LIBRARY'] = r'C:\Program Files\Python36\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Program Files\Python36\tcl\tcl8.6'
executables=[cx_Freeze.Executable('CeasarCypher.py')]
cx_Freeze.setup(name='CeasarCypher',version='0.1',description='foda',
options={'build_exe':{'packages':['tkinter']}},
executables=executables,
)
1
Author: Caio Roberto, 2017-10-13
1 answers
The problem is here:
janela.title('Convertor da Cifra de César')
You need to put the encoding at the beginning of the code. So python can recognize unicode characters.
#encoding: utf-8
import tkinter as tk
from tkinter import *
import random
Or run with python3, it will not be necessary to put #encoding: utf-8
If you want to know more about encodings: Encoding utf-8 allows accents?
1
Author: Samuel Haidu, 2017-10-14 21:03:28