import requests
from tkinter import *
from tkinter import messagebox
# Configure sua chave de API da News API
API_KEY = 'Obter_chave'
# Função para buscar notícias da API
def fetch_news():
url = f'https://newsapi.org/v2/top-headlines?country=us&apiKey={API_KEY}'
response = requests.get(url)
if response.status_code == 200:
news_data = response.json()
display_news(news_data['articles'])
else:
messagebox.showerror("Erro", "Não foi possível buscar as notícias.")
# Função para exibir as notícias na interface
def display_news(articles):
news_text.delete(1.0, END)
for article in articles:
news_text.insert(END, f"Title: {article['title']}\n")
news_text.insert(END, f"Description: {article['description']}\n\n")
# Configuração da interface gráfica
root = Tk()
root.title("Leitor de Notícias")
root.geometry("600x400")
title_label = Label(root, text="Leitor de Notícias", font=("Arial", 24))
title_label.pack(pady=10)
news_text = Text(root, wrap=WORD, font=("Arial", 12))
news_text.pack(expand=True, fill=BOTH)
fetch_button = Button(root, text="Buscar Notícias", command=fetch_news, font=("Arial", 14))
fetch_button.pack(pady=10)
root.mainloop()