Skip to content

Instantly share code, notes, and snippets.

@rodrigo-x
Last active March 27, 2021 06:26
Show Gist options
  • Save rodrigo-x/58287eaf4fd66ebdfef89b2bbd19b398 to your computer and use it in GitHub Desktop.
Save rodrigo-x/58287eaf4fd66ebdfef89b2bbd19b398 to your computer and use it in GitHub Desktop.
Consome API com TK
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Consome a API de Cotação do Dólar
"""
import tkinter as tk
import json
import requests
root = tk.Tk()
URL = 'http://economia.awesomeapi.com.br/json/all/USD-BRL'
request = requests.get(URL)
dados_da_moeda = json.loads(request.content)
USD_na_alta = dados_da_moeda['USD']['high']
USD_na_baixa = dados_da_moeda['USD']['low']
texto = tk.Text(font=('arial 12 bold'), bg='#183055', fg='#e6e0c9',
width='28', height='7', selectbackground='green2',
selectforeground='gray10')
texto.place(x=7, y=7)
texto.insert(tk.INSERT, '\n Dólar na alta:')
texto.insert(tk.INSERT, '\n ' +USD_na_alta)
texto.insert(tk.INSERT, '\n\n Dólar na baixa: ')
texto.insert(tk.INSERT, '\n ' +USD_na_baixa)
root.title('Cotação do DÓLAR')
root.config(background='#ffffff')
root.geometry('270x150+10+20')
root.resizable(False, False)
root.iconbitmap(r'C:\Users\rodri\OneDrive\Área de Trabalho\nasa.ico')
root.eval('tk::PlaceWindow . center')
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment