Last active
August 4, 2021 14:36
-
-
Save rodrigo-x/56b1c2a46f53f3b29509788b0e21f13e to your computer and use it in GitHub Desktop.
tkinter + request
This file contains hidden or 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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
import tkinter as tk | |
import requests | |
from parsel import Selector | |
from tkinter import ttk | |
from tk_html_widgets import HTMLLabel | |
from time import strftime | |
root = tk.Tk() | |
def relogio(): | |
label_r = ttk.Label(root, text = '') | |
label_r.place(x = 320, y = 15) | |
string = strftime('%H:%M:%S %p') | |
label_r.config(text = string, background = '#0099EE', | |
foreground = '#ffffff') | |
label_r.after(1000, relogio) | |
relogio() | |
label = HTMLLabel(root, html=""" | |
<div style="background-color:#0099EE"> | |
<img src='home\rodrigo\guia.png'> | |
</div> | |
""") | |
label.place(x = 35, y = 12) | |
label.fit_height() | |
label.config(background = '#0099EE') | |
label_um = HTMLLabel(root, html=""" | |
<div style="background-color:#0099EE;"> | |
<h2 style="color:#ffffff;">Escolha um canal:</h2> | |
</div> | |
""") | |
label_um.place(x = 50, y = 90) | |
label_um.fit_height() | |
label_um.config(background = '#0099EE') | |
# Não gosto de fazer isso.. Funções com tantas responsabilidades, mas o Tkinter me obrigou.. | |
def selecionado(event): | |
canal = combo.get().lstrip() | |
response = requests.get(f'https://meuguia.tv/programacao/canal/{canal}').text | |
s = Selector(response) | |
programacao = s.css('h2::text').get(), s.css('div.time::text').get() | |
label_dois = HTMLLabel(root, html=f""" | |
<div style="background-color:#0099EE;text-align:center"> | |
<h2 style="color:#ffffff;">Horário: {programacao[1]}</h2> | |
<h2 style="color:#ffffff;">{programacao[0]}</h2> | |
</div> | |
""") | |
label_dois.place(x = -134, y = 180) | |
label_dois.fit_height() | |
label_dois.config(background = '#0099EE') | |
n = tk.StringVar() | |
combo = ttk.Combobox(root, width = 27, | |
textvariable = n) | |
combo['values'] = (' GRD', | |
' HBO', | |
' MTV', | |
' CNN', | |
' TNT', | |
' TC2', | |
' TC1') | |
combo.grid(column = 1, row = 15) | |
combo.current(1) | |
combo.place(x = 52, y = 130) | |
combo.bind("<<ComboboxSelected>>", selecionado) | |
root.title('GUIA TV - PROGRAMAÇÃO') | |
root.geometry('400x300') | |
root.resizable(False, False) | |
root.config(background = '#0099EE') | |
root.iconbitmap(r'home\rodrigo\tv.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