lunes, 6 de mayo de 2019

U3 - Importa una imagen desde la wed (Aportacion)


import base64
try:
    # Python2
    import Tkinter as tk
    from urllib2 import urlopen
except ImportError:
    # Python3
    import tkinter as tk
    from urllib.request import urlopen
root = tk.Tk()
root.title("Implementar imagenes desde la web")
# margenes
w = 800
h = 600
x = 80
y = 100
# usar width x height + x_offset + y_offset (no spaces!)
root.geometry("%dx%d+%d+%d" % (w, h, x, y))
# cualquier imagen de la red
image_url = "https://media.giphy.com/media/10h1BGkwYiIydi/giphy.gif"
image_byt = urlopen(image_url).read()
image_b64 = base64.encodestring(image_byt)
photo = tk.PhotoImage(data=image_b64)
# SE CREA UN CANVAS BLANCO
cv = tk.Canvas(bg='white')
cv.pack(side='top', fill='both', expand='yes')
# SE COLOCA LA IMAGEN EN EL CANVAS
# CREAR_IMAGEN(xpos, ypos, image, anchor)
cv.create_image(10, 10, image=photo, anchor='nw')
root.mainloop()

No hay comentarios.:

Publicar un comentario

Unidad 3 - Configuracion y Administracion del Espacio en Disco

3.1 Estructuras logicas de almacenamiento. Para la gestión del almacenamiento de una base de datos existen 4 conceptos bien definidos que ...