associação pythonbrasil[11] django zope/plone planet Início Logado como (Entrar)

Diferenças para "CalculadoraComercial"

Diferenças entre as versões de 1 e 15 (14 versões de distância)
Revisão 1e 2006-04-25 12:34:14
Tamanho: 10501
Comentário:
Revisão 15e 2006-05-05 12:23:53
Tamanho: 33111
Comentário:
Deleções são marcadas assim. Adições são marcadas assim.
Linha 1: Linha 1:
= Calculadora Comercial =

Esta é uma calculadora que opera semelhante a calculadora do windows(possui memória,raiz quadrada, etc...).Porem ela tambem possui um espaço que imita uma fita de impressão, como uma calculadora comercial.

Foi feita com Tkinter.

== Código ==


{{{
#!python
Linha 5: Linha 17:
Autor:   Vinicius Rodrigues da Cunha Perallis Autores: Vinicius Rodrigues da Cunha Perallis
                                           
Linha 8: Linha 22:
Projeto: Calculadora que trabalha que imita uam fita de
impressão
                     22/04/2006
                     23/04/2006
                     24/04/2006
                     25/04/2006
                     26/04/2006
                     28/04/2006
                     29/04/2006
                     01/04/2006
                     
Projeto: Calculadora Comercial(imita uma fita de impressão)
Materia: Linguagens de Programação Comerciais
Linha 11: Linha 34:
Sistema Operacional: Linux
Sistemas Compativeis:Windows,Linux,Solaris,etc...

Disponível: http://www.pythonbrasil.com.br

Contato: perallis@rc.unesp.br
Linha 17: Linha 45:
#Importa as funções seno,cossseno,tangente,sqrt que
#é usada pela calculadora
from math import *
Linha 22: Linha 53:
    #método Construtor para iniializar a aplicação
Linha 23: Linha 55:
        self.myapp=parent         
 
self.myapp=parent
Linha 25: Linha 58:
        #cria o menu
 self.menubar = Menu(self.myapp)
        self.myapp.config(menu=self.menubar)
        # adiciona o file ao menu
        file = Menu(self.menubar)
        file.add_command(label='Sair',command=self.sair)
        self.menubar.add_cascade(label='Arquivo', \
                                 underline=0, menu=file)
         

        # Adiciona o help ao menu
        help = Menu(self.menubar)
        help.add_command(label='Autores',command=self.autores)
        help.add_command(label='Licença',command=self.licenca)
        help.add_command(label='Como usar?',\
                         command=self.comousar)
        self.menubar.add_cascade(label='Ajuda', underline=0, \
                                 menu=help)
 
Linha 29: Linha 81:
        #Cria os frames nescessarios para a disposição dos widgets no
programa
        #Cria os frames nescessarios para a disposição
       #dos widgets
Linha 37: Linha 89:
                  #Caixa de texto, que servirá para mostrar os numeros
        
self.visor=Entry(self.fexibir,width=23,bg="white",fg="blue",justify="right")
        self.visor.insert(INSERT,0)
        # Frame geral: Escreve um titulo na primeira linha do programa
        self.titulo=Label(self.geral,text=" CALCULADORA PYTHON
",bg="gray",fg="black",font=('Helvetica','10','bold'))
        # Insere a cixa de Texto que seá utilizada para fazer a fita de
impressão
        self.fcinco=Frame(self.geral,bg="gray")

        #Caixa de texto, que servirá para mostrar os
        #numeros
        self.visor=Entry(self.fexibir,width=35,bg="white",\
                         fg="blue",justify="right")
        self.visor.insert(INSERT,"0,")

 #Este trecho de coigo é nescessário para criar
        #os grupos dos botões radio
 self.decimais=IntVar()
        self.habilita=IntVar()
        self.decimais=1
        self.habilita=2
        
 #Botões de rádio , para opcão do nbumero de
        #casas decimais
        self.duascasas=Radiobutton(self.fexibir,\
                                   text="2 casas",\
                                   bg="gray",\
                                   variable=self.decimais, \
                                   command=lambda \
                                   casadec="%.2f": \
                                   self.mudcasadec(casadec))
        self.quatrocasas=Radiobutton(self.fexibir,\
                                     text="4 casas",\
                                     value=3,\
                                     variable=self.decimais, \
                                     bg="gray",command=lambda \
         casadec="%.4f":
                                     self.mudcasadec(casadec))
        self.infinitascasas=Radiobutton(self.fexibir,\
                                        text="... casas ",\
             variable=self.decimais,\
                                        value=4,bg="gray",\
                                        command=lambda \
             casadec="%f": \
                                    self.mudcasadec(casadec))

 #Frame Criado para inserir os botoes de radio
        #habilita/desabilita
        self.festado=Frame(self.geral,bg="gray")
        self.festado.pack(side="bottom")

        #Botões de rádio, para habilitar/desabilitar a
        #fita de impressão
        self.ativado=Radiobutton(self.festado,text="Ativar",\
                                 bg="gray",\
     variable=self.habilita, \
                                 command=lambda : \
                                 self.habilitar(h))
        self.desativado=Radiobutton(self.festado,text="Desativar",\
                                    value=2,\
        variable=self.habilita,\
                                    bg="gray",command=lambda h=2: \
        self.habilitar(h))

        #Espaco para melhor posicionar os botoes habilita/desabilita
 self.espaco=Label(self.festado,text=" \
                                                          ",bg="gray")
        self.espaco.pack(side="left")
        
 #Exibe os Botões de rádio , para habilitar ou desabilitar
        #a fita
        self.ativado.pack(side="left",padx=12,anchor=W)
        self.desativado.pack(side="left",padx=4,anchor=W)
        
        
        # Insere a caixa de Texto que será utilizada para
        #fazer a fita de impressão
Linha 49: Linha 160:
        self.ffita.pack(side="right",padx=15)         self.ffita.pack(side="right",padx=15,pady=5)
Linha 51: Linha 162:
        
self.fita=Text(self.ffita,width=23,height=13,bg="white",yscrollcommand=self.sb.set)
        self.fita=Text(self.ffita,width=23,height=16,\
                       
bg="white",\
                       
yscrollcommand=self.sb.set,\
                       relief="ridge"
)
Linha 58: Linha 171:
        ## WIDGETS NO FRAME ZERO
#########################################################
 ## WIDGETS NO FRAME ZERO #####################
Linha 61: Linha 173:
         self.c=Button(self.fzero,text="C",bg="white",width=4,command=self.zera)         self.c=Button(self.fzero,text="C",fg="red",\
                      width=7,command=self.zera)
        #Botao para limpar apenas o que esta no visor
        self.ce=Button(self.fzero,text="CE",fg="red",\
                       width=7,command=self.zeraprim)
        #Botao Backspace
        self.back=Button(self.fzero,text="Backspace",\
                         fg="red",width=10,\
                         command=self.volta)
Linha 64: Linha 183:
        self.space1=Label(self.fzero,bg="gray",text="
")
        #Botao igual
        
self.igual=Button(self.fzero,text="=",bg="white",width=4,command=lambda sin="": self.op(sin))
        
###################################################################################
        self.v=StringVar()
        self.v.set(" ")
        self.space1=Label(self.fzero,bg="gray",\
                          textvariable=self.v,\
                          relief="groove")
        ##############################################
        
Linha 73: Linha 192:
        ## WIDGETS NO FRAME UM
############################################################
        self.sete=Button(self.fum,text="7",width=4,command=lambda n=7:
self.write_visor(n))
        self.oito=Button(self.fum,text="8",width=4,command=lambda n=8:
self.write_visor(n))
        self.nove=Button(self.fum,text="9",width=4,command=lambda n=9:
self.write_visor(n))
        self.div=Button(self.fum,text="/",fg="red",width=4,
command=lambda sin='/': self.op(sin))
        
###################################################################################

        ## WIDGETS NO FRAME DOIS
############################################################
        self.quatro=Button(self.fdois,text="4",width=4,command=lambda
n=4: self.write_visor(n))
        self.cinco=Button(self.fdois,text="5",width=4,command=lambda
n=5: self.write_visor(n))
        self.seis=Button(self.fdois,text="6",width=4,command=lambda
n=6: self.write_visor(n))
        self.mult=Button(self.fdois,text="*",fg="red",width=4
,command=lambda sin='*': self.op(sin))
        
###################################################################################

        ## WIDGETS NO FRAME TREIS
##########################################################
        self.um=Button(self.ftreis,text="1",width=4,command=lambda n=1:
self.write_visor(n) )
        self.dois=Button(self.ftreis,text="2",width=4,command=lambda
n=2: self.write_visor(n))
        self.tres=Button(self.ftreis,text="3",width=4,command=lambda
n=3: self.write_visor(n))
        self.menos=Button(self.ftreis,text="-",fg="red",width=4,
command=lambda sin='-': self.op(sin) )
        
###################################################################################

        ## WIDGETS NO FRAME
QUATRO#########################################################
        self.zero=Button(self.fquatro,text="0",width=4,command=lambda
n=0: self.write_visor(n))
        self.virg=Button(self.fquatro,text=",",width=4,command=lambda
n='.': self.write_visor(n))
        self.maismenos=Button(self.fquatro,fg="red",text="+/-",width=4,
command=lambda n=-1: self.write_visor(n))
        self.mais=Button(self.fquatro,fg="red",text="+",width=4,
command=lambda sin='+': self.op(sin))
        
###################################################################################

        #Frame fgeral
        self.titulo.pack()
        ## WIDGETS NO FRAME UM #######################
        self.mc=Button(self.fum,text="MC",fg="red",\
                       width=4,command=lambda opm='MC': \
                       self.memoria(opm))
        self.sete=Button(self.fum,text="7",width=4,\
                         command=lambda n=7:\
                         self.write_visor(n))
        self.oito=Button(self.fum,text="8",width=4,\
                         command=lambda n=8: \
                         self.write_visor(n))
        self.nove=Button(self.fum,text="9",width=4,\
                         command=lambda n=9: \
                         self.write_visor(n))
        self.div=Button(self.fum,text="/",fg="red",\
                        width=4, command=lambda sin='/': \
                        self.op(sin))
        self.sqrt=Button(self.fum,text="sqrt",width=4,\
                         fg="blue",command=lambda \
                         n='sqrt': self.write_visor(n))
        ##############################################

        ## WIDGETS NO FRAME DOIS #####################
        self.mr=Button(self.fdois,text="MR",fg="red",\
                       width=4,command=lambda opm='MR': \
                       self.memoria(opm))
        self.quatro=Button(self.fdois,text="4",width=4,\
                           command=lambda n=4: \
                           self.write_visor(n))
        self.cinco=Button(self.fdois,text="5",width=4,\
                          command=lambda n=5: \
                          self.write_visor(n))
        self.seis=Button(self.fdois,text="6",width=4,\
                         command=lambda n=6: \
                         self.write_visor(n))
        self.mult=Button(self.fdois,text="*",fg="red",\
                         width=4 ,command=lambda sin='*': \
                         self.op(sin))
        self.umx=Button(self.fdois,text="1/x",width=4,\
                        fg="blue",command=lambda n='1/x'\
                        : self.write_visor(n))
        ###############################################

        ## WIDGETS NO FRAME TREIS ######################
        self.ms=Button(self.ftreis,text="MS",fg="red",\
                       width=4,command=lambda opm='MS': \
                       self.memoria(opm))
        self.um=Button(self.ftreis,text="1",width=4,\
                       command=lambda n=1:\
                       self.write_visor(n) )
        self.dois=Button(self.ftreis,text="2",\
                         width=4,command=lambda n=2: \
                         self.write_visor(n))
        self.tres=Button(self.ftreis,text="3",width=4,\
                         command=lambda n=3: self.write_visor(n))
        self.menos=Button(self.ftreis,text="-",fg="red",\
                          width=4, command=lambda sin='-': \
                          self.op(sin) )
        self.porcentagem=Button(self.ftreis,text="%",\
                                width=4,fg="blue",\
                                command=lambda n='%': \
                                self.write_visor(n))
        #################################################

        ## WIDGETS NO FRAME QUATRO#########################
        self.mmais=Button(self.fquatro,text="M+",fg="red",
                          width=4,command=lambda opm='M+': \
                          self.memoria(opm))
        self.zero=Button(self.fquatro,text="0",width=4,\
                         command=lambda n=0: \
                         self.write_visor(n))
        self.virg=Button(self.fquatro,text=",",width=4,\
                         command=lambda n='.': \
                         self.write_visor(n))
        self.maismenos=Button(self.fquatro,fg="blue",text="+/-",\
                              width=4, command=lambda n=-1: \
                              self.write_visor(n))
        self.mais=Button(self.fquatro,fg="red",text="+",width=4, \
                         command=lambda sin='+': self.op(sin))
        self.igual=Button(self.fquatro,text="=",fg="red",width=4,\
                          command=lambda sin="=": self.op(sin))
        ####################################################

        ## WIDGETS NO FRAME CINCO#########################
        self.mmenos=Button(self.fcinco,text="M-",fg="red",
                          width=4,command=lambda opm='M-': \
                          self.memoria(opm))
        self.centena=Button(self.fcinco,fg="brown",text="00",\
                            width=4, command=lambda n=100: \
                            self.write_visor(n))
        self.milhares=Button(self.fcinco,fg="brown",text="000",\
                             width=4, command=lambda n=1000: \
                             self.write_visor(n))
        self.mmenos=Button(self.fcinco,text="M-",fg="red",
                          width=4,command=lambda opm='M-': \
                          self.memoria(opm))
        self.seno=Button(self.fcinco,text="sen",fg="brown",
                          width=4,command=lambda n='sen': \
                          self.write_visor(n))
        self.cosseno=Button(self.fcinco,text="cos",fg="brown",
                          width=4,command=lambda n='cos': \
                          self.write_visor(n))
        self.tangente=Button(self.fcinco,text="tan",fg="brown",
                          width=4,command=lambda n='tan': \
                          self.write_visor(n))
        ####################################################
        
Linha 129: Linha 300:
        self.fexibir.pack()         self.fexibir.pack(padx=10,pady=10)
Linha 132: Linha 303:
        self.duascasas.pack(side="left",padx=12,anchor=W)
        self.quatrocasas.pack(side="left",padx=4,anchor=W)
        self.infinitascasas.pack(side="left",padx=4,anchor=W)
Linha 134: Linha 308:
        self.fzero.pack()
       
        self.c.pack(side=LEFT,fill=X,pady="5",padx="2")
        self.igual.pack(side=LEFT,fill=X,pady="5",padx="2")
        self.space1.pack()
        self.fzero.pack()
 
        self.space1.pack(side="left",padx="5")
        self.c.pack(side="left",pady="5",padx="3")
        self.ce.pack(side="left",pady="5",padx="3")
        self.back.pack(side="left",pady="5",padx="3")
        
Linha 141: Linha 317:
        self.fum.pack()
   
        self.fum.pack(padx=2)
        
        self.mc.pack(side="left",padx=4,pady=2)
Linha 147: Linha 324:
        self.sqrt.pack(side="left",padx=2,pady=2)
Linha 149: Linha 327:
        self.fdois.pack()         self.fdois.pack(padx=2)

        self.mr.pack(side="left",padx=4,pady=2)
        self.quatro.pack(side="left",padx=2,pady=2)
        self.cinco.pack(side="left",padx=2,pady=2)
Linha 151: Linha 333:
        self.cinco.pack(side="left",padx=2,pady=2)
        self.quatro.pack(side="left",padx=2,pady=2)
Linha 154: Linha 334:
        self.umx.pack(side="left",padx=2,pady=2)
Linha 156: Linha 337:
        self.ftreis.pack()         self.ftreis.pack(padx=2)

        self.ms.pack(side="left",padx=4,pady=2)
        self.um.pack(side="left",padx=2,pady=2)
        self.dois.pack(side="left",padx=2,pady=2)
Linha 158: Linha 343:
        self.dois.pack(side="left",padx=2,pady=2)
        self.um.pack(side="left",padx=2,pady=2)
Linha 161: Linha 344:
        self.porcentagem.pack(side="left",padx=2,pady=2)
Linha 163: Linha 347:
        self.fquatro.pack()         self.fquatro.pack(padx=2)

        self.mmais.pack(side="left",padx=4,pady=2)
Linha 168: Linha 354:
                 # Variais da classe         self.igual.pack(side="left",padx=2,pady=2)

        #Frame fcinco
        self.fcinco.pack(padx=2)

        self.mmenos.pack(side="left",padx=4,pady=2)
        self.centena.pack(side="left",padx=2,pady=2)
        self.milhares.pack(side="left",padx=2,pady=2)
        self.seno.pack(side="left",padx=2,pady=2)
        self.cosseno.pack(side="left",padx=2,pady=2)
        self.tangente.pack(side="left",padx=2,pady=2)
         
        
        # Variais booleanas da classe
Linha 172: Linha 370:
        self.atual=0
Linha 175: Linha 372:
        self.num=0
Linha 179: Linha 375:
                       ###------------------------------Função para realizar as operações
aritiméticas --------------------------###
        
        self.sinais=1
        self.i=0
        self.prim_op=0
        
 #Controle do numero de vezes que o usario clica
 #na virgula
 self.ponto=1
        
 #Variaveis usadas para guardar os valores do visor
        self.atual=0
        self.num=0
        self.mem=0


        self.casadec="%.2f"

    #metodo para mudar o numero de casas decimais
    def mudcasadec(self,casadec):
        self.casadec=casadec
   

    #-#--------------- Função aritmética op -------------#-#
Linha 187: Linha 398:
        if (self.w==0):         if (self.w==0) and self.prim_op==1:
Linha 189: Linha 400:
            print self.num             self.atual=float(self.visor.get())
            self.fita.insert(INSERT,self.num)
Linha 194: Linha 406:
            self.ty=0             self.ty=1
Linha 196: Linha 408:
            self.sinais=1
            self.prim=1
            self.ponto=1
Linha 199: Linha 414:
        else :         elif self.prim_op==1:
            
            if sin=="=" and self.i==1 and self.ty==1:
                self.sinais=1
                
            if sin!="=" and self.ty==1:
                self.sinal=sin
                self.sinais=0
                self.atual=float(self.visor.get())
                
Linha 202: Linha 426:
                                            
Linha 207: Linha 431:
     if self.sinal=='+':      if self.sinal=='+' and self.sinais==1:
Linha 209: Linha 433:
            elif self.sinal=='-':                 self.i=0
elif self.sinal=='-' and self.sinais==1:
Linha 211: Linha 436:
            elif self.sinal=='/' and self.ty!=1 and self.atual!=0:             elif self.sinal=='/' and self.sinais==1 and \
                
self.atual!=0:
                self.i=0
Linha 213: Linha 440:
            elif self.sinal=='/' and self.atual==0 and self.ty!=1:             elif self.sinal=='/' and self.atual==0 and \
                 
self.sinais==1:
         self.zera()
Linha 217: Linha 446:
  self.prim=1
            elif self.sinal=='*' and self.ty!=1 and self.prim==1:
  self.sinais=0
            elif self.sinal=='*' and self.prim==1 and \
                 
self.sinais==1:
                self.i=0
Linha 223: Linha 454:
                self.visor.insert(END,self.num)                 self.visor.insert(END,self.casadec %self.num)
Linha 225: Linha 456:
            if self.divi==0 and self.ty==0:             if (self.divi==0 and self.ty==0) or self.sinais==1:
                
Linha 229: Linha 461:
                self.fita.insert(INSERT,"\n"+str(self.num))
            
                                         
            self.atual=0
                self.fita.insert(INSERT,"\n "+\
                                 self.casadec %self.num)

            if sin!="=" and sin!=self.sinal and self.ty==0:
                self.sinais=0
                self.sinal=sin
                self.sinal=sin
                                                    
Linha 237: Linha 473:
            self.div=0 
            self.sinal=sin
    ###----------------------------------------
Fim da funçõa
aritmética op --------------------------------------###




    ###-------------------------
------- Função para escrever os numeros
no visor ---------------------------------###
            self.div=0
            self.sinais=1
            se
lf.ponto=1
    #-#--------------
Fim da função aritmética op ---------#-#



    #+#
------- Função para escrever os numeros no visor ----#+#
Linha 248: Linha 482:
        if (self.z==1) and n!=-1:         if (self.z==1) and n!=-1 and n!="1/x" and n!="sqrt" \
           and n!="%" and n!='.' and n!=100 and n!=1000 \
           and n!="sen" and n!="cos" \
           and n!="tan":
Linha 258: Linha 495:
       
        
            self.i=1
            self.prim_op=1
Linha 261: Linha 498:
        elif self.z==0 and n!=-1:         elif self.z==0 and n!=-1 and n!="1/x" and n!="sqrt" \
             and n!="%" and n!='.'and n!=100 and n!=1000 \
             and n!="sen" and n!="cos" \
             and n!="tan":
Linha 265: Linha 505:
            self.fita.insert(INSERT,n)             
Linha 269: Linha 509:
        if n==-1:
            self.la=float(self.visor.get()) * (-1)
            self.i=1
            self.prim_op=1

        el
if n==-1 and self.prim_op==1:
            self.la=(float(self.visor.get())*(-1))
Linha 272: Linha 515:
            self.visor.insert(END,self.la)
self.fita.insert(INSERT,"\n"+"*(-1)")
            self.fita.insert(INSERT,"\n"+"=")
            self.fita.insert(INSERT,"\n"+str(self.la))
            self.visor.insert(END,self.casadec %self.la)
            if self.ty==1:
    
self.fita.insert(INSERT,"\n"+"*(-1)")
                self.fita.insert(INSERT,"\n"+"=")
                self.fita.insert(INSERT,"\n "+\
                                 self.casadec %self.la)
Linha 277: Linha 522:
                ###---------------------------------------- Fim da funçõa
write_visor --------------------------------------###
       


    ###---------------------------------- Função para reiniciar a calculadora ----------------------------------###
            self.i=0
            self.prim_op=1
          

        elif n=="1/x" and self.prim_op==1:
            try:
                self.la=float(1/float(self.visor.get()))
                self.visor.delete(0,END)
                self.visor.insert(END,self.casadec %self.la)
                if self.ty==1:
                    self.fita.insert(INSERT,"**(-1)")
                    self.fita.insert(INSERT,"\n"+"=")
                    self.fita.insert(INSERT,"\n "+\
                                     self.casadec %self.la)
                self.sa=1
                self.i=0
            except:
                 self.visor.delete(0,END)
        
 elif n=="sqrt" and self.prim_op==1:
            try:
                self.la=sqrt(float(self.visor.get()))
                self.visor.delete(0,END)
                self.visor.insert(END,self.casadec %self.la)
                if self.ty==1:
                    self.fita.insert(INSERT,"\n"+"sqrt")
                    self.fita.insert(INSERT,"\n"+"=")
                    self.fita.insert(INSERT,"\n "+\
                                     self.casadec %self.la)
                    
                self.sa=1
                self.i=0
            except:
                self.zera()
                self.visor.delete(0,END)
                self.visor.insert(END,\
                                  "Valor invalido para função")

        elif n=="sen" and self.prim_op==1:
            try:
                self.la=sin((float(self.visor.get())/180)*pi)
                self.visor.delete(0,END)
                self.visor.insert(END,self.casadec %self.la)
                if self.ty==1:
                    self.fita.insert(INSERT,"\n"+"sen")
                    self.fita.insert(INSERT,"\n"+"=")
                    self.fita.insert(INSERT,"\n " \
                                     +self.casadec %self.la)
                self.sa=1
                self.i=0
            except:
                self.zera()
                self.visor.delete(0,END)
                self.visor.insert(END,\
                                  "Valor invalido para função")
                
        elif n=="cos" and self.prim_op==1:
            try:
               
                self.la=cos((float(self.visor.get())/180)*pi)
                self.visor.delete(0,END)
                self.visor.insert(END,self.casadec %self.la)
                if self.ty==1:
                    self.fita.insert(INSERT,"\n"+"cos")
                    self.fita.insert(INSERT,"\n"+"=")
                    self.fita.insert(INSERT,"\n "\
                                     +self.casadec %self.la)
                self.sa=1
                self.i=0
            except:
                self.zera()
                self.visor.delete(0,END)
                self.visor.insert(END,"Valor invalido para função")
                
        elif n=="tan" and self.prim_op==1:
            try:
                self.la=tan((float(self.visor.get())/180)*pi)
                self.visor.delete(0,END)
                self.visor.insert(END,self.casadec %self.la)
                if self.ty==1:
                    self.fita.insert(INSERT,"\n"+"tan")
                    self.fita.insert(INSERT,"\n"+"=")
                    self.fita.insert(INSERT,"\n "\
                                     +self.casadec %self.la)
                self.sa=1
                self.i=0
            except:
                self.zera()
                self.visor.delete(0,END)
        
 elif n=="%" and self.ty==0 and self.prim_op==1 \
             and self.z==1:
            self.perc=float(self.visor.get())
            self.la=self.num*(float(self.visor.get()))/100
            self.visor.delete(0,END)
            self.visor.insert(END,self.casadec %self.la)
            if self.ty==1:
                self.fita.insert(INSERT,"\n"+"*")
                self.fita.insert(INSERT,"\n"+\
                                 str(self.perc/100))
                self.fita.insert(INSERT,"\n"+"%")
                self.fita.insert(INSERT,"\n"+"=")
                self.fita.insert(INSERT,"\n "+\
                                 self.casadec %self.la)
            self.sa=1
            self.i=1

        elif n=="%" and self.ty==1 and self.prim_op==1 \
             and self.z==1:
            self.perc=float(self.visor.get())
            self.la=((float(self.visor.get()))*\
                     (float(self.visor.get())))/100
            self.visor.delete(0,END)
            self.visor.insert(END,self.casadec %self.la)
            if self.ty==1:
                self.fita.insert(INSERT,"\n"+"*")
                self.fita.insert(INSERT,"\n"+ \
                                 str(self.perc/100))
                self.fita.insert(INSERT,"\n"+"=")
                self.fita.insert(INSERT,"\n "+\
                                 self.casadec %self.la)
            self.sa=1
            self.i=1

        elif n=="%" and self.ty==0 and self.prim_op==1 \
             and self.z==0:
            self.perc=float(self.visor.get())
            self.la=((float(self.visor.get()))*(0))/100
            self.visor.delete(0,END)
            self.visor.insert(END,self.casadec %self.la)
            if self.ty==0:
                self.fita.insert(INSERT,"\n"+"*")
                self.fita.insert(INSERT,"\n"+str(0/100))
                self.fita.insert(INSERT,"\n"+"=")
                self.fita.insert(INSERT,"\n "\
                                 +self.casadec %self.la)
            self.sa=1
            self.i=1


        elif n=='.' and self.ponto==1:
            self.visor.insert(INSERT,n)
            if self.z==0:
                self.fita.insert(INSERT,n)
            self.ponto=0

        
        elif n==100 and self.prim_op==1:
            try:
                self.la=(float(self.visor.get()))*n
                self.visor.delete(0,END)
                self.visor.insert(END,self.casadec %self.la)
                if self.ty==1:
                    self.fita.insert(INSERT,"\n"+"*100")
                    self.fita.insert(INSERT,"\n"+"=")
                    self.fita.insert(INSERT,"\n "\
                                     +self.casadec %self.la)
                self.sa=1
                self.i=1
            except:
                self.zera()
                self.visor.delete(0,END)
                self.visor.insert(END,\
                                  "Valor invalido para função")

        elif n==1000 and self.prim_op==1:
            try:
                self.la=(float(self.visor.get()))*n
                self.visor.delete(0,END)
                self.visor.insert(END,self.casadec %self.la)
                if self.ty==1:
                    self.fita.insert(INSERT,"\n"+"*1000")
                    self.fita.insert(INSERT,"\n"+"=")
                    self.fita.insert(INSERT,"\n "\
                                     +self.casadec %self.la)
                self.sa=1
                self.i=1
            except:
                self.zera()
                self.visor.delete(0,END)
                self.visor.insert(END,"Valor invalido para função")
    #-#--------- Fim da função write_visor ------------#-#


    
    #+#-------Função para manipular a memória----------#+#

    def memoria(self,opm):
        if opm=="MC":
            self.mem=0
            self.v.set(" ")
            
        elif opm=="MR":
             self.visor.delete(0,END)
             self.visor.insert(INSERT,str(self.mem))
             self.i=0
             self.ty=0
        elif opm=="MS":
            self.mem=float(self.visor.get())
            self.v.set(" M ")
            self.i=0
        elif opm=="M+":
            self.mem=self.mem + float(self.visor.get())
            self.v.set(" M ")
            self.i=0
        elif opm=="M-":
            self.mem=self.mem - float(self.visor.get())
            self.v.set(" M ")
            self.i=0
    #-#------------------- Fim Memoria ---- -------------#-#


    #+#------- Função para reiniciar a calculadora ------#+#
Linha 285: Linha 736:
 self.num=0
Linha 291: Linha 741:
        self.num=0
Linha 292: Linha 743:
        self.h=0
        self.sa=0
        self.sinais=1
        self.i=0
        self.prim_op=0
        self.ponto=1
Linha 295: Linha 752:
    ###------------------------------------------- Fim da função
zera-------------------------------------------###
       
        
    #-#----------------- Fim da função zera -------------#-#


    #+#-------------------- Função CE -------------------#+#
    def zeraprim(self):
 if self.ty==0:
            self.visor.delete(0,END)
            self.visor.insert(INSERT,0)
            self.i=0
            
        else:
            self.zera()
    #-#----------------- Fim da função CE ----------------#-#
 
     
    #+#-------------- Função volta(Backspace) ------------#+#
    def volta(self):
        if self.ty==0 and self.prim_op==1:
            tam = len(self.visor.get())
            self.visor.delete(tam-1,tam)
    #-#----------------- Fim da função volta--------------#-#


    #+#------------------- Função Habilita ---------------#+#
    def habilitar(self,h):
        if h==2:
            self.fita["state"]="disabled"
        if h==1:
            self.fita["state"]="normal"
    #-#---------------- Fim da função Habilita-------------#-#


    #+#-----------------Janela Sobre(Autores)--------------#+#
    def autores(self):
                s = """
Autores:
Vinícius Rodrigues da Cunha Perallis
UNESP, Rio Claro
Instituto de Geociências e Ciências Exatas IGCE
Email: perallis@rc.unesp.br
  """
                message_box = Toplevel()
                message_box.title("Autores:")
                message_box_fr = Frame(message_box)
                message_box_fr.pack(expand=0, fill=BOTH)
                message_lb = Label(message_box_fr, text = s,\
       justify="left")
                message_lb.grid(row=0, column=0)
                quitbutton = Button(message_box_fr,\
         text = 'Fechar', \
                                    command=message_box.destroy,\
        borderwidth=1)
                quitbutton.grid(row=1, column=0)
    #-#----------------Fim de Janela Sobre(Autores)----------#-#


    #+#------------------Janela Sobre(Licenca)---------------#+#
    def licenca(self):
                s = """
Licença: O uso deste programa é gratuito.
              Seu código pode ser melhorado, ou alterado
              conforme a nescessidade do usuário

                    Email: perallis@rc.unesp.br
  """
                message_box = Toplevel()
                message_box.title("Licença:")
                message_box_fr = Frame(message_box)
                message_box_fr.pack(expand=0, fill=BOTH)
                message_lb = Label(message_box_fr, text = s,\
             justify="left")
                message_lb.grid(row=0, column=0)
                quitbutton = Button(message_box_fr,\
        text = 'Fechar', \
        command=message_box.destroy,\
        borderwidth=1)
                quitbutton.grid(row=1, column=0)
    #-#-----------Fim de Janela Licenca(Autores)-------------#-#


    #+#------------------Janela ComoUsar(Licenca)------------#+#
    def comousar(self):
                s = """
Como Usar: Esta é uma calculadora que opera como qualquer
                  outra calculadora(semelhante a do windows).
                  A unica diferença,é que ela imita uma fita
                  de impressão, como uma calculadora comercial

                       Email: perallis@rc.unesp.br
    """
                message_box = Toplevel()
                message_box.title("Como usar?")
                message_box_fr = Frame(message_box)
                message_box_fr.pack(expand=0, fill=BOTH)
                message_lb = Label(message_box_fr, text = s,\
              justify="left")
                message_lb.grid(row=0, column=0)
                quitbutton = Button(message_box_fr, \
                                    text = 'Fechar', \
                                    command=message_box.destroy,\
        borderwidth=1)
                quitbutton.grid(row=1, column=0)
    #-#----------------Fim de Janela ComoUsar(Autores)-------#-#


    #+#-------------- Função para sair do programa ----------#+#
    def sair(self):
 root.destroy()
    #-#--------------------- Fim Fnção sair -----------------#-#
Linha 305: Linha 867:
}}}

Calculadora Comercial

Esta é uma calculadora que opera semelhante a calculadora do windows(possui memória,raiz quadrada, etc...).Porem ela tambem possui um espaço que imita uma fita de impressão, como uma calculadora comercial.

Foi feita com Tkinter.

Código

   1 #!/usr/bin/python
   2 # -*- coding: cp1252 -*-
   3 
   4 """
   5 Autores:             Vinicius Rodrigues da Cunha Perallis
   6                      
   7                      
   8 Data:                19/04/2006
   9                      20/04/2006
  10                      22/04/2006
  11                      23/04/2006
  12                      24/04/2006
  13                      25/04/2006
  14                      26/04/2006
  15                      28/04/2006
  16                      29/04/2006
  17                      01/04/2006
  18                      
  19 Projeto:             Calculadora Comercial(imita uma fita de impressão)
  20 Materia:             Linguagens de Programação Comerciais
  21 Interpretador:       Python 2.4.1
  22 
  23 Sistemas Compativeis:Windows,Linux,Solaris,etc...
  24 
  25 Disponível:          http://www.pythonbrasil.com.br
  26 
  27 Contato:             perallis@rc.unesp.br
  28 """
  29 
  30 
  31 #Importa todas funcoes do modulo Tkinter
  32 from Tkinter import *
  33 #Importa as funções seno,cossseno,tangente,sqrt que 
  34 #é usada pela calculadora
  35 from math import *
  36 
  37 
  38 #Classe Principal que executa o aplicativo Calculadora
  39 class Calculadora:
  40     
  41     #método Construtor para iniializar a aplicação      
  42     def __init__(self,parent):
  43         
  44         self.myapp=parent
  45         self.myapp.title("Calculadora - Phy")
  46         #cria o menu
  47         self.menubar = Menu(self.myapp)
  48         self.myapp.config(menu=self.menubar)
  49         # adiciona o file ao menu
  50         file = Menu(self.menubar)
  51         file.add_command(label='Sair',command=self.sair)
  52         self.menubar.add_cascade(label='Arquivo', \
  53                                  underline=0, menu=file)
  54          
  55 
  56         # Adiciona o help ao menu
  57         help = Menu(self.menubar)
  58         help.add_command(label='Autores',command=self.autores)
  59         help.add_command(label='Licença',command=self.licenca)
  60         help.add_command(label='Como usar?',\
  61                          command=self.comousar)
  62         self.menubar.add_cascade(label='Ajuda', underline=0, \
  63                                  menu=help)
  64  
  65         #Cria o frame principa
  66         self.geral=Frame(self.myapp,bg="gray")
  67         self.geral.pack()
  68         
  69         #Cria os frames nescessarios para a disposição
  70         #dos widgets
  71         self.fexibir=Frame(self.geral,bg="gray")
  72         self.fzero=Frame(self.geral,bg="gray")
  73         self.fum=Frame(self.geral,bg="gray")
  74         self.fdois=Frame(self.geral,bg="gray")
  75         self.ftreis=Frame(self.geral,bg="gray")
  76         self.fquatro=Frame(self.geral,bg="gray")
  77         self.fcinco=Frame(self.geral,bg="gray")
  78 
  79         #Caixa de texto, que servirá para mostrar os
  80         #numeros
  81         self.visor=Entry(self.fexibir,width=35,bg="white",\
  82                          fg="blue",justify="right")
  83         self.visor.insert(INSERT,"0,") 
  84 
  85         #Este trecho de coigo é nescessário para criar
  86         #os grupos dos botões radio
  87         self.decimais=IntVar()
  88         self.habilita=IntVar()
  89         self.decimais=1
  90         self.habilita=2
  91         
  92         #Botões de rádio , para opcão do nbumero de
  93         #casas decimais
  94         self.duascasas=Radiobutton(self.fexibir,\
  95                                    text="2 casas",\
  96                                    bg="gray",\
  97                                    variable=self.decimais, \
  98                                    command=lambda \
  99                                    casadec="%.2f": \
 100                                    self.mudcasadec(casadec))
 101         self.quatrocasas=Radiobutton(self.fexibir,\
 102                                      text="4 casas",\
 103                                      value=3,\
 104                                      variable=self.decimais, \
 105                                      bg="gray",command=lambda \
 106                                      casadec="%.4f": 
 107                                      self.mudcasadec(casadec))
 108         self.infinitascasas=Radiobutton(self.fexibir,\
 109                                         text="... casas ",\
 110                                                 variable=self.decimais,\
 111                                         value=4,bg="gray",\
 112                                         command=lambda \
 113                                                 casadec="%f": \
 114                                     self.mudcasadec(casadec))  
 115 
 116         #Frame Criado para inserir os botoes de radio
 117         #habilita/desabilita
 118         self.festado=Frame(self.geral,bg="gray")
 119         self.festado.pack(side="bottom")
 120 
 121         #Botões de rádio, para habilitar/desabilitar a
 122         #fita de impressão
 123         self.ativado=Radiobutton(self.festado,text="Ativar",\
 124                                  bg="gray",\
 125                                  variable=self.habilita, \
 126                                  command=lambda : \
 127                                  self.habilitar(h))
 128         self.desativado=Radiobutton(self.festado,text="Desativar",\
 129                                     value=2,\
 130                                     variable=self.habilita,\
 131                                     bg="gray",command=lambda h=2: \
 132                                     self.habilitar(h))
 133 
 134         #Espaco para melhor posicionar os botoes habilita/desabilita
 135         self.espaco=Label(self.festado,text="                        \
 136                                                           ",bg="gray")
 137         self.espaco.pack(side="left") 
 138         
 139         #Exibe os Botões de rádio , para habilitar ou desabilitar
 140         #a fita 
 141         self.ativado.pack(side="left",padx=12,anchor=W)
 142         self.desativado.pack(side="left",padx=4,anchor=W)
 143         
 144         
 145         # Insere a caixa de Texto que será utilizada para
 146         #fazer a fita de impressão
 147         self.ffita=Frame(self.geral)
 148         self.ffita.pack(side="right",padx=15,pady=5)
 149         self.sb=Scrollbar(self.ffita)
 150         self.fita=Text(self.ffita,width=23,height=16,\
 151                        bg="white",\
 152                        yscrollcommand=self.sb.set,\
 153                        relief="ridge")
 154         self.sb["command"] = self.fita.yview
 155         self.fita.pack(side="left",padx=0)
 156         self.sb.pack(side="right",fill=Y)
 157         
 158         
 159         ## WIDGETS NO FRAME ZERO #####################
 160         #Botao para reiniciar a calculadora
 161         self.c=Button(self.fzero,text="C",fg="red",\
 162                       width=7,command=self.zera)
 163         #Botao para limpar apenas o que esta no visor 
 164         self.ce=Button(self.fzero,text="CE",fg="red",\
 165                        width=7,command=self.zeraprim)
 166         #Botao Backspace
 167         self.back=Button(self.fzero,text="Backspace",\
 168                          fg="red",width=10,\
 169                          command=self.volta)
 170         #Label para organizar o programa
 171         self.v=StringVar()
 172         self.v.set("         ")
 173         self.space1=Label(self.fzero,bg="gray",\
 174                           textvariable=self.v,\
 175                           relief="groove")
 176         ##############################################
 177         
 178 
 179        
 180         ## WIDGETS NO FRAME UM #######################
 181         self.mc=Button(self.fum,text="MC",fg="red",\
 182                        width=4,command=lambda opm='MC': \
 183                        self.memoria(opm))
 184         self.sete=Button(self.fum,text="7",width=4,\
 185                          command=lambda n=7:\
 186                          self.write_visor(n))
 187         self.oito=Button(self.fum,text="8",width=4,\
 188                          command=lambda n=8: \
 189                          self.write_visor(n))
 190         self.nove=Button(self.fum,text="9",width=4,\
 191                          command=lambda n=9: \
 192                          self.write_visor(n))
 193         self.div=Button(self.fum,text="/",fg="red",\
 194                         width=4, command=lambda sin='/': \
 195                         self.op(sin))
 196         self.sqrt=Button(self.fum,text="sqrt",width=4,\
 197                          fg="blue",command=lambda \
 198                          n='sqrt': self.write_visor(n))
 199         ##############################################
 200 
 201         ## WIDGETS NO FRAME DOIS #####################
 202         self.mr=Button(self.fdois,text="MR",fg="red",\
 203                        width=4,command=lambda opm='MR': \
 204                        self.memoria(opm))
 205         self.quatro=Button(self.fdois,text="4",width=4,\
 206                            command=lambda n=4: \
 207                            self.write_visor(n))
 208         self.cinco=Button(self.fdois,text="5",width=4,\
 209                           command=lambda n=5: \
 210                           self.write_visor(n))
 211         self.seis=Button(self.fdois,text="6",width=4,\
 212                          command=lambda n=6: \
 213                          self.write_visor(n))
 214         self.mult=Button(self.fdois,text="*",fg="red",\
 215                          width=4 ,command=lambda sin='*': \
 216                          self.op(sin))
 217         self.umx=Button(self.fdois,text="1/x",width=4,\
 218                         fg="blue",command=lambda n='1/x'\
 219                         : self.write_visor(n))
 220         ###############################################
 221 
 222         ## WIDGETS NO FRAME TREIS ######################
 223         self.ms=Button(self.ftreis,text="MS",fg="red",\
 224                        width=4,command=lambda opm='MS': \
 225                        self.memoria(opm))
 226         self.um=Button(self.ftreis,text="1",width=4,\
 227                        command=lambda n=1:\
 228                        self.write_visor(n) )
 229         self.dois=Button(self.ftreis,text="2",\
 230                          width=4,command=lambda n=2: \
 231                          self.write_visor(n))
 232         self.tres=Button(self.ftreis,text="3",width=4,\
 233                          command=lambda n=3: self.write_visor(n))
 234         self.menos=Button(self.ftreis,text="-",fg="red",\
 235                           width=4, command=lambda sin='-': \
 236                           self.op(sin) )
 237         self.porcentagem=Button(self.ftreis,text="%",\
 238                                 width=4,fg="blue",\
 239                                 command=lambda n='%': \
 240                                 self.write_visor(n))
 241         #################################################
 242 
 243         ## WIDGETS NO FRAME QUATRO#########################
 244         self.mmais=Button(self.fquatro,text="M+",fg="red",
 245                           width=4,command=lambda opm='M+': \
 246                           self.memoria(opm))
 247         self.zero=Button(self.fquatro,text="0",width=4,\
 248                          command=lambda n=0: \
 249                          self.write_visor(n))
 250         self.virg=Button(self.fquatro,text=",",width=4,\
 251                          command=lambda n='.': \
 252                          self.write_visor(n))
 253         self.maismenos=Button(self.fquatro,fg="blue",text="+/-",\
 254                               width=4, command=lambda n=-1: \
 255                               self.write_visor(n))
 256         self.mais=Button(self.fquatro,fg="red",text="+",width=4, \
 257                          command=lambda sin='+': self.op(sin))
 258         self.igual=Button(self.fquatro,text="=",fg="red",width=4,\
 259                           command=lambda sin="=": self.op(sin))
 260         ####################################################
 261 
 262         ## WIDGETS NO FRAME CINCO#########################
 263         self.mmenos=Button(self.fcinco,text="M-",fg="red",
 264                           width=4,command=lambda opm='M-': \
 265                           self.memoria(opm))
 266         self.centena=Button(self.fcinco,fg="brown",text="00",\
 267                             width=4, command=lambda n=100: \
 268                             self.write_visor(n))
 269         self.milhares=Button(self.fcinco,fg="brown",text="000",\
 270                              width=4, command=lambda n=1000: \
 271                              self.write_visor(n))
 272         self.mmenos=Button(self.fcinco,text="M-",fg="red",
 273                           width=4,command=lambda opm='M-': \
 274                           self.memoria(opm))
 275         self.seno=Button(self.fcinco,text="sen",fg="brown",
 276                           width=4,command=lambda n='sen': \
 277                           self.write_visor(n))
 278         self.cosseno=Button(self.fcinco,text="cos",fg="brown",
 279                           width=4,command=lambda n='cos': \
 280                           self.write_visor(n))
 281         self.tangente=Button(self.fcinco,text="tan",fg="brown",
 282                           width=4,command=lambda n='tan': \
 283                           self.write_visor(n))
 284         ####################################################
 285         
 286          
 287         #Frame fexibir   
 288         self.fexibir.pack(padx=10,pady=10)
 289        
 290         self.visor.pack(ipadx="3")
 291         self.duascasas.pack(side="left",padx=12,anchor=W)
 292         self.quatrocasas.pack(side="left",padx=4,anchor=W)
 293         self.infinitascasas.pack(side="left",padx=4,anchor=W)
 294    
 295         #Frame fzero  
 296         self.fzero.pack()
 297         
 298         self.space1.pack(side="left",padx="5")
 299         self.c.pack(side="left",pady="5",padx="3")
 300         self.ce.pack(side="left",pady="5",padx="3")
 301         self.back.pack(side="left",pady="5",padx="3")
 302         
 303 
 304         #Frame fum   
 305         self.fum.pack(padx=2)
 306         
 307         self.mc.pack(side="left",padx=4,pady=2)
 308         self.sete.pack(side="left",padx=2,pady=2)
 309         self.oito.pack(side="left",padx=2,pady=2)
 310         self.nove.pack(side="left",padx=2,pady=2)
 311         self.div.pack(side="left",padx=2,pady=2)
 312         self.sqrt.pack(side="left",padx=2,pady=2)
 313         
 314         #Frame fdois   
 315         self.fdois.pack(padx=2)
 316 
 317         self.mr.pack(side="left",padx=4,pady=2)
 318         self.quatro.pack(side="left",padx=2,pady=2)
 319         self.cinco.pack(side="left",padx=2,pady=2)
 320         self.seis.pack(side="left",padx=2,pady=2)
 321         self.mult.pack(side="left",padx=2,pady=2)
 322         self.umx.pack(side="left",padx=2,pady=2)
 323 
 324         #Frame ftreis 
 325         self.ftreis.pack(padx=2)
 326 
 327         self.ms.pack(side="left",padx=4,pady=2)
 328         self.um.pack(side="left",padx=2,pady=2)
 329         self.dois.pack(side="left",padx=2,pady=2)
 330         self.tres.pack(side="left",padx=2,pady=2)
 331         self.menos.pack(side="left",padx=2,pady=2)
 332         self.porcentagem.pack(side="left",padx=2,pady=2)
 333 
 334         #Frame fquatro   
 335         self.fquatro.pack(padx=2)
 336 
 337         self.mmais.pack(side="left",padx=4,pady=2)
 338         self.maismenos.pack(side="left",padx=2,pady=2)
 339         self.zero.pack(side="left",padx=2,pady=2)
 340         self.virg.pack(side="left",padx=2,pady=2)
 341         self.mais.pack(side="left",padx=2,pady=2)
 342         self.igual.pack(side="left",padx=2,pady=2)
 343 
 344         #Frame fcinco   
 345         self.fcinco.pack(padx=2)
 346 
 347         self.mmenos.pack(side="left",padx=4,pady=2)
 348         self.centena.pack(side="left",padx=2,pady=2)
 349         self.milhares.pack(side="left",padx=2,pady=2)
 350         self.seno.pack(side="left",padx=2,pady=2)
 351         self.cosseno.pack(side="left",padx=2,pady=2)
 352         self.tangente.pack(side="left",padx=2,pady=2)
 353          
 354         
 355         #  Variais booleanas da classe 
 356         self.z=0
 357         self.w=1
 358         self.i=0
 359         self.ty=0
 360         self.prim=0
 361         self.h=0
 362         self.sa=0
 363         self.sinais=1
 364         self.i=0
 365         self.prim_op=0
 366         
 367         #Controle do numero de vezes que o usario clica
 368         #na virgula
 369         self.ponto=1        
 370         
 371         #Variaveis usadas para guardar os valores do visor
 372         self.atual=0
 373         self.num=0
 374         self.mem=0
 375 
 376 
 377         self.casadec="%.2f"
 378 
 379     #metodo para mudar o numero de casas decimais       
 380     def mudcasadec(self,casadec):
 381         self.casadec=casadec
 382    
 383 
 384     #-#--------------- Função aritmética op -------------#-#        
 385     def op(self,sin):
 386         if (self.w==0) and self.prim_op==1:
 387             self.num=float(self.visor.get())
 388             self.atual=float(self.visor.get())
 389             self.fita.insert(INSERT,self.num)
 390             self.sinal=sin
 391             self.w=1
 392             self.z=1
 393             self.i=0 
 394             self.ty=1
 395             self.divi=0
 396             self.sinais=1
 397             self.prim=1
 398             self.ponto=1
 399             if self.prim==0:
 400                 self.ty=1
 401                 
 402         elif self.prim_op==1:   
 403             
 404             if sin=="=" and self.i==1 and self.ty==1: 
 405                 self.sinais=1
 406                 
 407             if sin!="=" and self.ty==1:
 408                 self.sinal=sin
 409                 self.sinais=0
 410                 self.atual=float(self.visor.get())
 411                 
 412             if self.ty==0:
 413                 self.atual=float(self.visor.get())
 414                            
 415             if self.sa==1 and self.ty==1:
 416                 self.num=float(self.visor.get())
 417                 self.sa=0
 418                 
 419             if self.sinal=='+' and self.sinais==1:
 420                 self.num=self.num + self.atual
 421                 self.i=0
 422             elif  self.sinal=='-' and self.sinais==1:
 423                 self.num=self.num - self.atual
 424             elif  self.sinal=='/' and self.sinais==1 and \
 425                  self.atual!=0:
 426                 self.i=0
 427                 self.num=self.num / self.atual
 428             elif  self.sinal=='/' and self.atual==0 and \
 429                  self.sinais==1:
 430                 self.zera()        
 431                 self.visor.delete(0,END)
 432                 self.visor.insert(INSERT,"Imposivel dividir")
 433                 self.divi=1
 434                 self.sinais=0
 435             elif  self.sinal=='*' and self.prim==1 and \
 436                  self.sinais==1:
 437                 self.i=0
 438                 self.num=self.num * self.atual
 439             
 440             if self.divi==0:
 441                 self.visor.delete(0,END)
 442                 self.visor.insert(END,self.casadec %self.num)
 443                 self.prim=1
 444             if (self.divi==0 and self.ty==0) or self.sinais==1:
 445                 
 446                 self.fita.insert(INSERT,"\n"+self.sinal)
 447                 self.fita.insert(INSERT,"\n"+str(self.atual))
 448                 self.fita.insert(INSERT,"\n"+"=")
 449                 self.fita.insert(INSERT,"\n "+\
 450                                  self.casadec %self.num)
 451 
 452             if sin!="=" and sin!=self.sinal and self.ty==0:
 453                 self.sinais=0
 454                 self.sinal=sin
 455                 self.sinal=sin
 456                                                     
 457             self.ty=1
 458             self.i=0
 459             self.w=1
 460             self.z=1
 461             self.div=0
 462             self.sinais=1
 463             self.ponto=1
 464     #-#--------------  Fim da função aritmética op ---------#-#
 465 
 466 
 467 
 468     #+#------- Função para escrever os numeros no visor ----#+#       
 469     def write_visor(self,n):
 470         if (self.z==1) and n!=-1 and n!="1/x" and  n!="sqrt" \
 471            and  n!="%" and n!='.' and n!=100 and n!=1000 \
 472            and n!="sen" and n!="cos" \
 473            and n!="tan":
 474             if self.i==0: 
 475                  self.visor.delete(0,END)         
 476           
 477             self.visor.insert(INSERT,n)
 478             self.w=1
 479             self.z=1
 480             self.i=1
 481             self.ty=0
 482             self.prim=1
 483             self.i=1
 484             self.prim_op=1
 485             
 486         elif self.z==0 and n!=-1 and n!="1/x" and  n!="sqrt" \
 487              and  n!="%" and n!='.'and n!=100 and n!=1000 \
 488              and n!="sen" and n!="cos" \
 489              and n!="tan":
 490             if self.i==0:
 491                 self.visor.delete(0,END)         
 492             self.visor.insert(INSERT,n)
 493             
 494             self.w=0
 495             self.i=1
 496             self.ty=0
 497             self.i=1
 498             self.prim_op=1
 499 
 500         elif  n==-1 and self.prim_op==1:
 501             self.la=(float(self.visor.get())*(-1))
 502             self.visor.delete(0,END)
 503             self.visor.insert(END,self.casadec %self.la)
 504             if self.ty==1:
 505                 self.fita.insert(INSERT,"\n"+"*(-1)")
 506                 self.fita.insert(INSERT,"\n"+"=")
 507                 self.fita.insert(INSERT,"\n "+\
 508                                  self.casadec %self.la)
 509             self.sa=1
 510             self.i=0
 511             self.prim_op=1
 512           
 513 
 514         elif  n=="1/x" and self.prim_op==1:
 515             try:
 516                 self.la=float(1/float(self.visor.get())) 
 517                 self.visor.delete(0,END)
 518                 self.visor.insert(END,self.casadec %self.la)
 519                 if self.ty==1:
 520                     self.fita.insert(INSERT,"**(-1)")
 521                     self.fita.insert(INSERT,"\n"+"=")
 522                     self.fita.insert(INSERT,"\n "+\
 523                                      self.casadec %self.la)
 524                 self.sa=1
 525                 self.i=0
 526             except:
 527                  self.visor.delete(0,END)
 528         
 529         elif  n=="sqrt" and self.prim_op==1:
 530             try:    
 531                 self.la=sqrt(float(self.visor.get()))
 532                 self.visor.delete(0,END)
 533                 self.visor.insert(END,self.casadec %self.la)
 534                 if self.ty==1:
 535                     self.fita.insert(INSERT,"\n"+"sqrt")
 536                     self.fita.insert(INSERT,"\n"+"=")
 537                     self.fita.insert(INSERT,"\n "+\
 538                                      self.casadec %self.la)
 539                     
 540                 self.sa=1
 541                 self.i=0
 542             except:
 543                 self.zera()
 544                 self.visor.delete(0,END)
 545                 self.visor.insert(END,\
 546                                   "Valor invalido para função")
 547 
 548         elif  n=="sen" and self.prim_op==1:
 549             try:    
 550                 self.la=sin((float(self.visor.get())/180)*pi)
 551                 self.visor.delete(0,END)
 552                 self.visor.insert(END,self.casadec %self.la)
 553                 if self.ty==1:
 554                     self.fita.insert(INSERT,"\n"+"sen")
 555                     self.fita.insert(INSERT,"\n"+"=")
 556                     self.fita.insert(INSERT,"\n " \
 557                                      +self.casadec %self.la)
 558                 self.sa=1
 559                 self.i=0
 560             except:
 561                 self.zera()
 562                 self.visor.delete(0,END)
 563                 self.visor.insert(END,\
 564                                   "Valor invalido para função")
 565                 
 566         elif  n=="cos" and self.prim_op==1:
 567             try:
 568                
 569                 self.la=cos((float(self.visor.get())/180)*pi)
 570                 self.visor.delete(0,END)
 571                 self.visor.insert(END,self.casadec %self.la)
 572                 if self.ty==1:
 573                     self.fita.insert(INSERT,"\n"+"cos")
 574                     self.fita.insert(INSERT,"\n"+"=")
 575                     self.fita.insert(INSERT,"\n "\
 576                                      +self.casadec %self.la)
 577                 self.sa=1
 578                 self.i=0
 579             except:
 580                 self.zera()
 581                 self.visor.delete(0,END)
 582                 self.visor.insert(END,"Valor invalido para função")
 583                 
 584         elif  n=="tan" and self.prim_op==1:
 585             try:    
 586                 self.la=tan((float(self.visor.get())/180)*pi)
 587                 self.visor.delete(0,END)
 588                 self.visor.insert(END,self.casadec %self.la)
 589                 if self.ty==1:
 590                     self.fita.insert(INSERT,"\n"+"tan")
 591                     self.fita.insert(INSERT,"\n"+"=")
 592                     self.fita.insert(INSERT,"\n "\
 593                                      +self.casadec %self.la)
 594                 self.sa=1
 595                 self.i=0
 596             except:
 597                 self.zera()
 598                 self.visor.delete(0,END)
 599         
 600         elif  n=="%" and self.ty==0 and self.prim_op==1 \
 601              and self.z==1:
 602             self.perc=float(self.visor.get())
 603             self.la=self.num*(float(self.visor.get()))/100
 604             self.visor.delete(0,END)
 605             self.visor.insert(END,self.casadec %self.la)
 606             if self.ty==1:
 607                 self.fita.insert(INSERT,"\n"+"*")
 608                 self.fita.insert(INSERT,"\n"+\
 609                                  str(self.perc/100))
 610                 self.fita.insert(INSERT,"\n"+"%")
 611                 self.fita.insert(INSERT,"\n"+"=")
 612                 self.fita.insert(INSERT,"\n "+\
 613                                  self.casadec %self.la)
 614             self.sa=1
 615             self.i=1
 616 
 617         elif  n=="%" and self.ty==1 and self.prim_op==1 \
 618              and self.z==1:
 619             self.perc=float(self.visor.get())
 620             self.la=((float(self.visor.get()))*\
 621                      (float(self.visor.get())))/100
 622             self.visor.delete(0,END)
 623             self.visor.insert(END,self.casadec %self.la)
 624             if self.ty==1:
 625                 self.fita.insert(INSERT,"\n"+"*")
 626                 self.fita.insert(INSERT,"\n"+ \
 627                                  str(self.perc/100))
 628                 self.fita.insert(INSERT,"\n"+"=")
 629                 self.fita.insert(INSERT,"\n "+\
 630                                  self.casadec %self.la)
 631             self.sa=1
 632             self.i=1
 633 
 634         elif  n=="%" and self.ty==0 and self.prim_op==1 \
 635              and self.z==0:
 636             self.perc=float(self.visor.get())
 637             self.la=((float(self.visor.get()))*(0))/100
 638             self.visor.delete(0,END)
 639             self.visor.insert(END,self.casadec %self.la)
 640             if self.ty==0:
 641                 self.fita.insert(INSERT,"\n"+"*")
 642                 self.fita.insert(INSERT,"\n"+str(0/100))
 643                 self.fita.insert(INSERT,"\n"+"=")
 644                 self.fita.insert(INSERT,"\n "\
 645                                  +self.casadec %self.la)
 646             self.sa=1
 647             self.i=1
 648 
 649 
 650         elif n=='.' and self.ponto==1:      
 651             self.visor.insert(INSERT,n)
 652             if self.z==0:
 653                 self.fita.insert(INSERT,n)
 654             self.ponto=0
 655 
 656         
 657         elif  n==100 and self.prim_op==1:
 658             try:    
 659                 self.la=(float(self.visor.get()))*n
 660                 self.visor.delete(0,END)
 661                 self.visor.insert(END,self.casadec %self.la)
 662                 if self.ty==1:
 663                     self.fita.insert(INSERT,"\n"+"*100")
 664                     self.fita.insert(INSERT,"\n"+"=")
 665                     self.fita.insert(INSERT,"\n "\
 666                                      +self.casadec %self.la)
 667                 self.sa=1
 668                 self.i=1
 669             except:
 670                 self.zera()
 671                 self.visor.delete(0,END)
 672                 self.visor.insert(END,\
 673                                   "Valor invalido para função")
 674 
 675         elif  n==1000 and self.prim_op==1:
 676             try:    
 677                 self.la=(float(self.visor.get()))*n
 678                 self.visor.delete(0,END)
 679                 self.visor.insert(END,self.casadec %self.la)
 680                 if self.ty==1:
 681                     self.fita.insert(INSERT,"\n"+"*1000")
 682                     self.fita.insert(INSERT,"\n"+"=")
 683                     self.fita.insert(INSERT,"\n "\
 684                                      +self.casadec %self.la)
 685                 self.sa=1
 686                 self.i=1
 687             except:
 688                 self.zera()
 689                 self.visor.delete(0,END)
 690                 self.visor.insert(END,"Valor invalido para função")
 691     #-#--------- Fim da função write_visor ------------#-#
 692 
 693 
 694     
 695     #+#-------Função para manipular a memória----------#+#
 696 
 697     def memoria(self,opm):
 698         if opm=="MC":
 699             self.mem=0
 700             self.v.set("         ")
 701             
 702         elif opm=="MR":
 703              self.visor.delete(0,END)         
 704              self.visor.insert(INSERT,str(self.mem))
 705              self.i=0
 706              self.ty=0
 707         elif opm=="MS":
 708             self.mem=float(self.visor.get())
 709             self.v.set("   M   ")
 710             self.i=0
 711         elif opm=="M+":
 712             self.mem=self.mem + float(self.visor.get())
 713             self.v.set("   M   ")
 714             self.i=0
 715         elif opm=="M-":
 716             self.mem=self.mem - float(self.visor.get())
 717             self.v.set("   M   ")
 718             self.i=0
 719     #-#------------------- Fim Memoria ---- -------------#-#
 720 
 721 
 722     #+#------- Função para reiniciar a calculadora ------#+#     
 723     def zera(self):
 724         self.z=0
 725         self.w=1
 726         self.atual=0
 727         self.i=0
 728         self.ty=0
 729         self.num=0
 730         self.prim=0
 731         self.h=0
 732         self.sa=0
 733         self.sinais=1
 734         self.i=0
 735         self.prim_op=0
 736         self.ponto=1
 737         self.visor.delete(0,END)
 738         self.visor.insert(INSERT,0)
 739         self.fita.delete('1.0','90.0')
 740     #-#----------------- Fim da função zera -------------#-#
 741 
 742 
 743     #+#-------------------- Função CE -------------------#+#    
 744     def zeraprim(self):
 745         if  self.ty==0:
 746             self.visor.delete(0,END)
 747             self.visor.insert(INSERT,0)
 748             self.i=0
 749             
 750         else:
 751             self.zera()
 752     #-#----------------- Fim da função CE ----------------#-#
 753         
 754         
 755     #+#-------------- Função volta(Backspace) ------------#+#    
 756     def volta(self):
 757         if self.ty==0 and self.prim_op==1:
 758             tam = len(self.visor.get())
 759             self.visor.delete(tam-1,tam)                
 760     #-#----------------- Fim da função volta--------------#-#
 761 
 762 
 763     #+#------------------- Função Habilita ---------------#+#    
 764     def habilitar(self,h):
 765         if h==2:
 766             self.fita["state"]="disabled"
 767         if h==1:
 768             self.fita["state"]="normal"
 769     #-#---------------- Fim da função Habilita-------------#-#
 770 
 771 
 772     #+#-----------------Janela Sobre(Autores)--------------#+#
 773     def autores(self):
 774                 s = """
 775 Autores:
 776 Vinícius Rodrigues da Cunha Perallis
 777 UNESP, Rio Claro
 778 Instituto de Geociências e Ciências Exatas IGCE 
 779 Email: perallis@rc.unesp.br
 780                 """
 781                 message_box = Toplevel()
 782                 message_box.title("Autores:")
 783                 message_box_fr = Frame(message_box)
 784                 message_box_fr.pack(expand=0, fill=BOTH)
 785                 message_lb = Label(message_box_fr, text = s,\
 786                                    justify="left")
 787                 message_lb.grid(row=0, column=0)
 788                 quitbutton = Button(message_box_fr,\
 789                                     text = 'Fechar', \
 790                                     command=message_box.destroy,\
 791                                     borderwidth=1)
 792                 quitbutton.grid(row=1, column=0)
 793     #-#----------------Fim de Janela Sobre(Autores)----------#-#
 794 
 795 
 796     #+#------------------Janela Sobre(Licenca)---------------#+#
 797     def licenca(self):
 798                 s = """
 799 Licença: O uso deste programa é gratuito.
 800               Seu código pode ser melhorado, ou alterado
 801               conforme a nescessidade do usuário
 802 
 803                     Email: perallis@rc.unesp.br
 804                 """
 805                 message_box = Toplevel()
 806                 message_box.title("Licença:")
 807                 message_box_fr = Frame(message_box)
 808                 message_box_fr.pack(expand=0, fill=BOTH)
 809                 message_lb = Label(message_box_fr, text = s,\
 810                                   justify="left")
 811                 message_lb.grid(row=0, column=0)
 812                 quitbutton = Button(message_box_fr,\
 813                                     text = 'Fechar', \
 814                                     command=message_box.destroy,\
 815                                     borderwidth=1)
 816                 quitbutton.grid(row=1, column=0)
 817     #-#-----------Fim de Janela Licenca(Autores)-------------#-#
 818 
 819 
 820     #+#------------------Janela ComoUsar(Licenca)------------#+#
 821     def comousar(self):
 822                 s = """
 823 Como Usar: Esta é uma calculadora que opera como qualquer
 824                   outra calculadora(semelhante a do windows).
 825                   A unica diferença,é que ela imita uma fita
 826                   de impressão, como uma calculadora comercial
 827 
 828                        Email: perallis@rc.unesp.br
 829                   """
 830                 message_box = Toplevel()
 831                 message_box.title("Como usar?")
 832                 message_box_fr = Frame(message_box)
 833                 message_box_fr.pack(expand=0, fill=BOTH)
 834                 message_lb = Label(message_box_fr, text = s,\
 835                                    justify="left")
 836                 message_lb.grid(row=0, column=0)
 837                 quitbutton = Button(message_box_fr, \
 838                                     text = 'Fechar', \
 839                                     command=message_box.destroy,\
 840                                     borderwidth=1)
 841                 quitbutton.grid(row=1, column=0)
 842     #-#----------------Fim de Janela ComoUsar(Autores)-------#-#
 843 
 844 
 845     #+#-------------- Função para sair do programa ----------#+#
 846     def sair(self):
 847         root.destroy()
 848     #-#--------------------- Fim Fnção sair -----------------#-#
 849 
 850             
 851 # root Intacia-se pela classe Tk() e inicia a aplicação       
 852 root=Tk()
 853 aplicativo=Calculadora(root)
 854 root.mainloop()