Advertisement
tutorfree

Flex-TK_v0.0.3

Sep 18th, 2020 (edited)
1,178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.26 KB | None | 0 0
  1. try:
  2.     from tkinter import *
  3. except:
  4.     from Tkinter import *
  5.  
  6. janela = Tk()
  7. janela.title("FlexTK")
  8.  
  9. def Limpar():
  10.     try:
  11.         alcool.delete(0, END)
  12.         gasolina.delete(0, END)
  13.         lbDivisao["text"] = ""
  14.         lbResultado["text"] = ""
  15.     except ValueError:
  16.         pass
  17.  
  18.  
  19. def nao_vazio(alcool, gasolina):
  20.         if Entry.get(alcool) != '' and Entry.get(gasolina) != '':
  21.             return True
  22.         else:
  23.             return False
  24.  
  25.  
  26. def e_numero(alcool, gasolina):
  27.         if Entry.get(alcool).replace(',', '', 1).isdigit() == True and\
  28.         Entry.get(gasolina).replace(',', '', 1).isdigit() == True:
  29.             return True
  30.         else:
  31.             return False
  32.  
  33.  
  34. def Divisao():
  35.         if nao_vazio(alcool, gasolina) == True and e_numero(alcool, gasolina) == True:
  36.  
  37.             precoAlcool = float(Entry.get(alcool).replace(',', '.', 1))
  38.             precoGasolina = float(Entry.get(gasolina).replace(',', '.', 1))
  39.             resultado = '%.2f %%' % (precoAlcool / precoGasolina*100)
  40.  
  41.             lbDivisao["text"] = str(resultado).replace('.', ',', 1)
  42.             if precoAlcool / precoGasolina < 0.7:
  43.                 lbResultado["text"] = "Compensa mais abastecer com álcool."
  44.             else:
  45.                 lbResultado["text"] = "Compensa mais abastecer com gasolina."
  46.         else:
  47.             lbResultado["text"] = "Um ou mais valores digitados estão fora do padrão!"
  48.  
  49. if __name__ == '__main__':
  50.  
  51.     lbAlcool = Label(janela, text="Álcool: ")
  52.     lbAlcool.place(x=20, y=40)
  53.    
  54.     lbGasolina = Label(janela, text="Gasolina: ")
  55.     lbGasolina.place(x=20, y=70)
  56.    
  57.     alcool = Entry(janela)
  58.     alcool.place(x=120, y=40, width=185)
  59.     alcool.focus_set()
  60.    
  61.     gasolina = Entry(janela)
  62.     gasolina.place(x=120, y=70, width=185)
  63.    
  64.     btCalcular = Button(janela, text="Calcular", width=7, command=Divisao)
  65.     btCalcular.place(x=120, y=110)
  66.    
  67.     btLimpar = Button(janela, text="Limpar", width=7, command=Limpar)
  68.     btLimpar.place(x=213, y=110)
  69.    
  70.     lbDivisao = Label(janela, text="", foreground="blue")
  71.     lbDivisao.place(x=20, y=150)
  72.    
  73.     lbResultado = Label(janela, text="")
  74.     lbResultado.place(x=20, y=170)
  75.    
  76.     janela.geometry("400x220+200+200")
  77.     janela.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement