Program closing immediately after opening (Post compiled)

1

I'm starting to study Tkinter and compiling, 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 opens a cmd and closes, without any kind of response, I tried to use True while before the code, but it did not work. 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()

Setup.py file code:

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,
      )
    
asked by anonymous 14.10.2017 / 01:12

1 answer

1

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 the 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'd like to know more about encodings: Encoding utf-8 allows accents?

    
14.10.2017 / 22:49