Program closing immediately after opening(Post-compiled)

Asked

Viewed 2,070 times

1

I’m starting to study Tkinter and compilation, and I have a basic Python notion, and I’m having some problems. Here’s an example of a basic program that, after compiling, the executable just quickly opens a cmd and closes, without any other kind of response, I’ve tried using while True before the code, but it has no effect.It must be something really stupid, 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()

Code of setup.py file:

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 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 perform with python3, it is not necessary to place #encoding: utf-8

If you want to know more about encodings: Encoding utf-8 allows accents?

  • I just did that, but after compiling again, you’re still in the same situation. I think there may be some error in the setup file, but I can’t say.Just for the sake of conscience, I’ll leave the setup code in the question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.