Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #Filename: alcoolORgasolina.py
- #Author: Antoine Paul
- #Date: 2016-JAN
- try:
- from tkinter import *
- except:
- from Tkinter import *
- janela = Tk()
- janela.title("Álcool ou Gasolina?")
- def Limpar():
- try:
- alcool.delete(0, END)
- gasolina.delete(0, END)
- lbDivisao["text"] = ""
- lbResultado["text"] = ""
- except ValueError:
- pass
- def Divisao():
- if Entry.get(alcool).replace('.', '', 1).isdigit() == True and Entry.get(gasolina).replace('.', '', 1).isdigit() == True:
- lbDivisao["text"] = '%.2f %%' %((float(Entry.get(alcool)) / float(Entry.get(gasolina)))*100)
- if float(Entry.get(alcool)) / float(Entry.get(gasolina)) < 0.7:
- lbResultado["text"] = "Compensa mais abastecer com álcool."
- else:
- lbResultado["text"] = "Compensa mais abastecer com gasolina."
- else:
- lbResultado["text"] = "Um ou mais valores digitados estão fora do padrão!"
- lbAlcool = Label(janela, text="Álcool: ")
- lbAlcool.place(x=50, y=40)
- lbGasolina = Label(janela, text="Gasolina: ")
- lbGasolina.place(x=50, y=70)
- alcool = Entry(janela)
- alcool.place(x=120, y=40, width=185)
- alcool.focus_set()
- gasolina = Entry(janela)
- gasolina.place(x=120, y=70, width=185)
- btCalcular = Button(janela, text="Calcular", width=7, command=Divisao)
- btCalcular.place(x=120, y=110)
- btLimpar = Button(janela, text="Limpar", width=7, command=Limpar)
- btLimpar.place(x=213, y=110)
- lbDivisao = Label(janela, text="", foreground="blue")
- lbDivisao.place(x=50, y=150)
- lbResultado = Label(janela, text="")
- lbResultado.place(x=50, y=170)
- janela.geometry("450x220+200+200")
- #icon = Image("photo", file = r'bomba.png')
- #janela.call('wm','iconphoto', janela._w, icon)
- janela.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement