Arquivo anexado 'calculadoraFitaimpressao.py'
Download 1 #!/usr/bin/python
2 # -*- coding: cp1252 -*-
3
4 """
5 Autor: Vinicius Rodrigues da Cunha Perallis
6 Data: 19/04/2006
7 20/04/2006
8 Projeto: Calculadora que trabalha que imita uam fita de impressão
9 Interpretador: Python 2.4.1
10 Sistema Operacional: Linux
11 """
12
13
14 #Importa todas funcoes do modulo Tkinter
15 from Tkinter import *
16
17
18 #Classe Principal que executa o aplicativo Calculadora
19 class Calculadora:
20
21 def __init__(self,parent):
22 self.myapp=parent
23 self.myapp.title("Calculadora - Phy")
24 #Cria o frame principa
25 self.geral=Frame(self.myapp,bg="gray")
26 self.geral.pack()
27
28 #Cria os frames nescessarios para a disposição dos widgets no programa
29 self.fexibir=Frame(self.geral,bg="gray")
30 self.fzero=Frame(self.geral,bg="gray")
31 self.fum=Frame(self.geral,bg="gray")
32 self.fdois=Frame(self.geral,bg="gray")
33 self.ftreis=Frame(self.geral,bg="gray")
34 self.fquatro=Frame(self.geral,bg="gray")
35
36
37 #Caixa de texto, que servirá para mostrar os numeros
38 self.visor=Entry(self.fexibir,width=23,bg="white",fg="blue",justify="right")
39 self.visor.insert(INSERT,0)
40 # Frame geral: Escreve um titulo na primeira linha do programa
41 self.titulo=Label(self.geral,text=" CALCULADORA PYTHON ",bg="gray",fg="black",font=('Helvetica','10','bold'))
42 # Insere a cixa de Texto que seá utilizada para fazer a fita de impressão
43 self.ffita=Frame(self.geral)
44 self.ffita.pack(side="right",padx=15)
45 self.sb=Scrollbar(self.ffita)
46 self.fita=Text(self.ffita,width=23,height=13,bg="white",yscrollcommand=self.sb.set)
47 self.sb["command"] = self.fita.yview
48 self.fita.pack(side="left",padx=0)
49 self.sb.pack(side="right",fill=Y)
50
51
52 ## WIDGETS NO FRAME ZERO #########################################################
53 #Botao para reiniciar a calculadora
54 self.c=Button(self.fzero,text="C",bg="white",width=4,command=self.zera)
55 #Label para organizar o programa
56 self.space1=Label(self.fzero,bg="gray",text=" ")
57 #Botao igual
58 self.igual=Button(self.fzero,text="=",bg="white",width=4,command=lambda sin="": self.op(sin))
59 ###################################################################################
60
61
62 ## WIDGETS NO FRAME UM ############################################################
63 self.sete=Button(self.fum,text="7",width=4,command=lambda n=7: self.write_visor(n))
64 self.oito=Button(self.fum,text="8",width=4,command=lambda n=8: self.write_visor(n))
65 self.nove=Button(self.fum,text="9",width=4,command=lambda n=9: self.write_visor(n))
66 self.div=Button(self.fum,text="/",fg="red",width=4, command=lambda sin='/': self.op(sin))
67 ###################################################################################
68
69 ## WIDGETS NO FRAME DOIS ############################################################
70 self.quatro=Button(self.fdois,text="4",width=4,command=lambda n=4: self.write_visor(n))
71 self.cinco=Button(self.fdois,text="5",width=4,command=lambda n=5: self.write_visor(n))
72 self.seis=Button(self.fdois,text="6",width=4,command=lambda n=6: self.write_visor(n))
73 self.mult=Button(self.fdois,text="*",fg="red",width=4 ,command=lambda sin='*': self.op(sin))
74 ###################################################################################
75
76 ## WIDGETS NO FRAME TREIS ##########################################################
77 self.um=Button(self.ftreis,text="1",width=4,command=lambda n=1: self.write_visor(n) )
78 self.dois=Button(self.ftreis,text="2",width=4,command=lambda n=2: self.write_visor(n))
79 self.tres=Button(self.ftreis,text="3",width=4,command=lambda n=3: self.write_visor(n))
80 self.menos=Button(self.ftreis,text="-",fg="red",width=4, command=lambda sin='-': self.op(sin) )
81 ###################################################################################
82
83 ## WIDGETS NO FRAME QUATRO#########################################################
84 self.zero=Button(self.fquatro,text="0",width=4,command=lambda n=0: self.write_visor(n))
85 self.virg=Button(self.fquatro,text=",",width=4,command=lambda n='.': self.write_visor(n))
86 self.maismenos=Button(self.fquatro,fg="red",text="+/-",width=4, command=lambda n=-1: self.write_visor(n))
87 self.mais=Button(self.fquatro,fg="red",text="+",width=4, command=lambda sin='+': self.op(sin))
88 ###################################################################################
89
90 #Frame fgeral
91 self.titulo.pack()
92
93 #Frame fexibir
94 self.fexibir.pack()
95
96 self.visor.pack(ipadx="3")
97
98 #Frame fzero
99 self.fzero.pack()
100
101 self.c.pack(side=LEFT,fill=X,pady="5",padx="2")
102 self.igual.pack(side=LEFT,fill=X,pady="5",padx="2")
103 self.space1.pack()
104
105 #Frame fum
106 self.fum.pack()
107
108 self.sete.pack(side="left",padx=2,pady=2)
109 self.oito.pack(side="left",padx=2,pady=2)
110 self.nove.pack(side="left",padx=2,pady=2)
111 self.div.pack(side="left",padx=2,pady=2)
112
113 #Frame fdois
114 self.fdois.pack()
115 self.seis.pack(side="left",padx=2,pady=2)
116 self.cinco.pack(side="left",padx=2,pady=2)
117 self.quatro.pack(side="left",padx=2,pady=2)
118 self.mult.pack(side="left",padx=2,pady=2)
119
120 #Frame ftreis
121 self.ftreis.pack()
122 self.tres.pack(side="left",padx=2,pady=2)
123 self.dois.pack(side="left",padx=2,pady=2)
124 self.um.pack(side="left",padx=2,pady=2)
125 self.menos.pack(side="left",padx=2,pady=2)
126
127 #Frame fquatro
128 self.fquatro.pack()
129 self.maismenos.pack(side="left",padx=2,pady=2)
130 self.zero.pack(side="left",padx=2,pady=2)
131 self.virg.pack(side="left",padx=2,pady=2)
132 self.mais.pack(side="left",padx=2,pady=2)
133
134 # Variais da classe
135 self.z=0
136 self.w=1
137 self.atual=0
138 self.i=0
139 self.ty=0
140 self.num=0
141 self.prim=0
142
143
144
145
146 ###------------------------------Função para realizar as operações aritiméticas --------------------------###
147
148 def op(self,sin):
149 if (self.w==0):
150 self.num=float(self.visor.get())
151 print self.num
152 self.sinal=sin
153 self.w=1
154 self.z=1
155 self.i=0
156 self.ty=0
157 self.divi=0
158 if self.prim==0:
159 self.ty=1
160
161 else :
162 if self.ty==0:
163 self.atual=float(self.visor.get())
164 if self.sinal=='+':
165 self.num=self.num + self.atual
166 elif self.sinal=='-':
167 self.num=self.num - self.atual
168 elif self.sinal=='/' and self.ty!=1 and self.atual!=0:
169 self.num=self.num / self.atual
170 elif self.sinal=='/' and self.atual==0 and self.ty!=1:
171 self.visor.delete(0,END)
172 self.visor.insert(INSERT,"Imposivel dividir")
173 self.divi=1
174 self.prim=1
175 elif self.sinal=='*' and self.ty!=1 and self.prim==1:
176 self.num=self.num * self.atual
177
178 else:
179 self.num=self.num
180 if self.divi==0:
181 self.visor.delete(0,END)
182 self.visor.insert(END,self.num)
183 self.prim=1
184 if self.divi==0 and self.ty==0:
185 self.fita.insert(INSERT,"\n"+self.sinal)
186 self.fita.insert(INSERT,"\n"+str(self.atual))
187 self.fita.insert(INSERT,"\n"+"=")
188 self.fita.insert(INSERT,"\n"+str(self.num))
189 self.atual=0
190 self.ty=1
191 self.i=0
192 self.w=1
193 self.z=1
194 self.div=0
195 self.sinal=sin
196 ###---------------------------------------- Fim da funçõa aritmética op --------------------------------------###
197
198
199
200
201 ###-------------------------------- Função para escrever os numeros no visor ---------------------------------###
202 def write_visor(self,n):
203 if (self.z==1)and n!=-1:
204 if self.i==0:
205 self.visor.delete(0,END)
206 self.visor.insert(INSERT,n)
207 self.z=1
208 self.w=1
209 self.i=1
210 self.ty=0
211 self.prim=1
212 elif n==-1:
213 self.num=float(self.visor.get())
214 self.visor.delete(0,END)
215 n=n*self.num
216 self.visor.insert(INSERT,n)
217 self.fita.insert("end","*(-1)")
218 self.w=0
219 else:
220 if self.i==0:
221 self.visor.delete(0,END)
222 self.visor.insert(INSERT,n)
223 self.w=0
224 self.i=1
225 self.ty=0
226 self.fita.insert(INSERT,n)
227 ###---------------------------------------- Fim da funçõa write_visor --------------------------------------###
228
229
230
231 ###---------------------------------- Função para reiniciar a calculadora ----------------------------------###
232 def zera(self):
233 self.num=0
234 self.z=0
235 self.w=1
236 self.atual=0
237 self.i=0
238 self.ty=0
239 self.prim=0
240 self.visor.delete(0,END)
241 self.visor.insert(INSERT,0)
242 self.fita.delete('1.0','90.0')
243 ###------------------------------------------- Fim da função zera-------------------------------------------###
244
245
246
247
248 # root Intacia-se pela classe Tk() e inicia a aplicação
249 root=Tk()
250 aplicativo=Calculadora(root)
251 root.mainloop()
Arquivos Anexados
Para se referir aos anexos de uma página, use attachment:filename, como mostrado abaixo na lista de arquivos. NÃO use a URL do link [get], já que a mesma está sujeita a alterações, e pode facilmente se tonar inválida.Você não tem permissão para anexar arquivos a esta página.