Created
October 31, 2014 02:34
-
-
Save maluta/2f95d1a96b5a2d87962f to your computer and use it in GitHub Desktop.
Programa simples: conversão milhas p/ quilômetros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tkinter import * | |
from tkinter import ttk | |
def calcular(*args): | |
try: | |
valor = float(milhas.get()) | |
quilometros.set(valor * 1.60934) | |
except ValueError: | |
pass | |
# definição da janela | |
base = Tk() | |
# definindo o título da janela | |
base.title("Millhas para Quilômetros") | |
janela_principal = ttk.Frame(base, padding="3 3 12 12") | |
janela_principal.grid(column=0, row=0, sticky=(N, W, E, S)) | |
janela_principal.columnconfigure(0, weight=1) | |
janela_principal.rowconfigure(0, weight=1) | |
milhas = StringVar() | |
quilometros = StringVar() | |
campo_milhas = ttk.Entry( janela_principal, width=7, textvariable=milhas) | |
campo_milhas.grid(column=2, row=1, stick=(W, E)) | |
ttk.Label( janela_principal, textvariable=quilometros).grid(column=2, row=2, stick=(W, E)) | |
ttk.Button( janela_principal, text = "Calcular", command=calcular).grid(column=3, row=3, sticky=W) | |
ttk.Label( janela_principal, text="milhas").grid(column=3, row=1, sticky=W) | |
ttk.Label( janela_principal, text="é igual a").grid(column=1, row=2, sticky=E) | |
ttk.Label( janela_principal, text="quilometros.").grid(column=3, row=2, sticky=W) | |
for child in janela_principal.winfo_children(): | |
child.grid_configure(padx=5, pady=5) | |
campo_milhas.focus() | |
base.bind('<Return>', calcular) | |
mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment