Skip to content

Commit

Permalink
Ejercicio 1 sprint2catalog.
Browse files Browse the repository at this point in the history
  • Loading branch information
ElbaCalvo committed Oct 16, 2023
1 parent 11b4daa commit aaf0466
Show file tree
Hide file tree
Showing 24 changed files with 85 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added sprint2catalog/__pycache__/cell.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file added sprint2catalog/__pycache__/window.cpython-311.pyc
Binary file not shown.
13 changes: 13 additions & 0 deletions sprint2catalog/cell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import tkinter as tk
from PIL import Image, ImageTk

class Cell:
def __init__(self, title, path, desc):
## Constructor.
self.title = title
self.path = path
self.desc = desc
## Reescalamos una imagen dándole nuevos valores al ancho y al alto.
foto = Image.open(self.path)
foto_red = foto.resize((100, 100), Image.Resampling.LANCZOS)
self.image_tk = ImageTk.PhotoImage(foto_red)
Binary file added sprint2catalog/data/edited/arandanos_ed.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprint2catalog/data/edited/manzana_ed.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprint2catalog/data/edited/naranja_ed.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprint2catalog/data/edited/pera_ed.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprint2catalog/data/edited/platano_ed.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprint2catalog/data/unedited/arandanos_uned.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprint2catalog/data/unedited/manzana_uned.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprint2catalog/data/unedited/naranja_uned.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprint2catalog/data/unedited/pera_uned.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sprint2catalog/data/unedited/platano_uned.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions sprint2catalog/detail_window.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from tkinter import ttk
import tkinter as tk
from PIL import Image, ImageTk
from cell import Cell

def detailWindow(cell):

## Creamos una ventana emergente con su respectivo título.
root = tk.Toplevel()
root.title("Descripción")

## Distintos label destinados a mostrar el título, la imagen y la descripción.
label1 = ttk.Label(root, text = cell.title)
label2 = ttk.Label(root, image = cell.image_tk)
label3 = ttk.Label(root, text = cell.desc)
label1.pack()
label2.pack()
label3.pack()

## Lanzamos el bucle principal.
root.mainloop()




10 changes: 10 additions & 0 deletions sprint2catalog/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from tkinter import Tk
from window import MainWindow

if __name__ == "__main__":
## Se crea una instancia de la clase Tk, que representa una ventana.
root = Tk()
## Guardamos la ventana en el root.
app = MainWindow(root)
## Lanzamos el bucle principal de la aplicación.
root.mainloop()
37 changes: 37 additions & 0 deletions sprint2catalog/window.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from tkinter import ttk
import tkinter as tk
from cell import Cell
from tkinter import messagebox
from detail_window import detailWindow

class MainWindow():

## En el button_on_clicked se crea la pestaña poniendole el título y el texto que se quiera.

##def on_button_clicked(self, cell):
## message = "Esto es un/a " + cell.title
## messagebox.showinfo("Frutas", message)

def __init__(self, root):
## El titulo de la pestaña.
root.title("Frutas")

## Hacemos una lista de celdas.
self.cells = [
Cell("Manzana", "C:\\msys64\\home\\Elba\\DI\\sprint1Tkinter\\catalog\\data\\unedited\\manzana_uned.jpg", "Fruta versátil y nutritiva, fuente de vitaminas y fibra, ideal para meriendas y platos saludables."),
Cell("Naranja", "C:\\msys64\\home\\Elba\\DI\\sprint1Tkinter\\catalog\\data\\unedited\\naranja_uned.jpg", "La naranja, fruta cítrica, es jugosa, dulce y llena de vitamina C, perfecta para refrescarse y disfrutar."),
Cell("Plátano", "C:\\msys64\\home\\Elba\\DI\\sprint1Tkinter\\catalog\\data\\unedited\\platano_uned.jpg", "Deliciosa fruta amarilla, fuente de energía y potasio, ideal para un snack saludable."),
Cell("Pera", "C:\\msys64\\home\\Elba\\DI\\sprint1Tkinter\\catalog\\data\\unedited\\pera_uned.jpg", "Fruta jugosa, dulce y rica en fibra, ideal para un bocado fresco y saludable."),
Cell("Arandanos", "C:\\msys64\\home\\Elba\\DI\\sprint1Tkinter\\catalog\\data\\unedited\\arandanos_uned.jpg", "Pequeñas joyas azules, llenas de antioxidantes y sabor fresco, perfectas para postres y desayunos.")
]

## Recorremos (con el enumerate), almacenando en cada iteración el elemento iterado y su posición.

for i, cell in enumerate(self.cells):

## Por cada iteración creamos una etiqueta label con su título e imagen.
label = ttk.Label(root, image = cell.image_tk, text=cell.title, compound = tk.BOTTOM)
## Agregamos la etiqueta a una matriz.
label.grid(row=0, column=i)
## Indicamos que label está pendiente de pulsar el botón izquierdo del ratón sobre la celda.
label.bind("<Button-1>", lambda event, celda = cell: detailWindow(celda))

0 comments on commit aaf0466

Please sign in to comment.