Advertisement
tutorfree

alcool ou gasolina?

Jan 29th, 2016 (edited)
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.83 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #Filename: alcoolORgasolina.py
  4. #Author: Antoine Paul
  5. #Date: 2016-JAN
  6.  
  7. try:
  8.     from tkinter import *
  9. except:
  10.     from Tkinter import *
  11.  
  12. janela = Tk()
  13. janela.title("Álcool ou Gasolina?")
  14.  
  15. def Limpar():
  16.     try:
  17.         alcool.delete(0, END)
  18.         gasolina.delete(0, END)
  19.         lbDivisao["text"] = ""
  20.         lbResultado["text"] = ""
  21.     except ValueError:
  22.         pass
  23.  
  24. def Divisao():
  25.  
  26.         if Entry.get(alcool).replace('.', '', 1).isdigit() == True and Entry.get(gasolina).replace('.', '', 1).isdigit() == True:
  27.  
  28.             lbDivisao["text"] = '%.2f %%' %((float(Entry.get(alcool)) / float(Entry.get(gasolina)))*100)
  29.             if float(Entry.get(alcool)) / float(Entry.get(gasolina)) < 0.7:
  30.                 lbResultado["text"] = "Compensa mais abastecer com álcool."
  31.             else:
  32.                 lbResultado["text"] = "Compensa mais abastecer com gasolina."
  33.         else:
  34.             lbResultado["text"] = "Um ou mais valores digitados estão fora do padrão!"
  35.  
  36. lbAlcool = Label(janela, text="Álcool: ")
  37. lbAlcool.place(x=50, y=40)
  38.  
  39. lbGasolina = Label(janela, text="Gasolina: ")
  40. lbGasolina.place(x=50, y=70)
  41.  
  42. alcool = Entry(janela)
  43. alcool.place(x=120, y=40, width=185)
  44. alcool.focus_set()
  45.  
  46. gasolina = Entry(janela)
  47. gasolina.place(x=120, y=70, width=185)
  48.  
  49. btCalcular = Button(janela, text="Calcular", width=7, command=Divisao)
  50. btCalcular.place(x=120, y=110)
  51.  
  52. btLimpar = Button(janela, text="Limpar", width=7, command=Limpar)
  53. btLimpar.place(x=213, y=110)
  54.  
  55. lbDivisao = Label(janela, text="", foreground="blue")
  56. lbDivisao.place(x=50, y=150)
  57.  
  58. lbResultado = Label(janela, text="")
  59. lbResultado.place(x=50, y=170)
  60.  
  61. janela.geometry("450x220+200+200")
  62. #icon = Image("photo", file = r'bomba.png')
  63. #janela.call('wm','iconphoto', janela._w, icon)
  64. janela.mainloop()
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement