This commit is contained in:
Juanjo 2024-12-03 10:10:36 +01:00
commit c6252a2b01
5 changed files with 379 additions and 0 deletions

37
graficos/graficos.py Normal file
View File

@ -0,0 +1,37 @@
import tkinter as tk
from tkinter import ttk
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
# Función para crear el gráfico de barras
def plot_barchart():
# Datos de ejemplo
categories = ['A', 'B', 'C', 'D', 'E']
values = [5, 7, 3, 8, 6]
# Limpiamos la figura antes de redibujar el gráfico
fig.clear()
ax = fig.add_subplot(111)
ax.bar(categories, values, color='skyblue')
ax.set_title("Gráfico de Barras de Ejemplo")
ax.set_xlabel("Categorías")
ax.set_ylabel("Valores")
# Actualizamos el canvas para mostrar el gráfico
canvas.draw()
# Configuración de la ventana principal
root = tk.Tk()
root.title("Gráfico de Barras con Tkinter y Matplotlib")
root.geometry("1000x900")
# Creamos una figura de matplotlib
fig = Figure(figsize=(5, 4), dpi=100)
canvas = FigureCanvasTkAgg(fig, master=root)
canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
# Botón para mostrar el gráfico
plot_button = ttk.Button(root, text="Mostrar Gráfico de Barras", command=plot_barchart)
plot_button.pack(side=tk.BOTTOM, pady=20)
root.mainloop()

32
graficos/responsive.py Normal file
View File

@ -0,0 +1,32 @@
import tkinter as tk
# Crear ventana principal
root = tk.Tk()
root.geometry("600x400") # Tamaño inicial
# Configurar la fila y columna principales para que se expandan
root.grid_rowconfigure(0, weight=1)
root.grid_columnconfigure(0, weight=1)
# Crear un frame principal y colocarlo en la ventana
main_frame = tk.Frame(root, bg="lightgray")
main_frame.grid(row=0, column=0, sticky="nsew")
# Configurar el frame para que se ajuste al tamaño de la ventana
main_frame.grid_rowconfigure(0, weight=1)
main_frame.grid_columnconfigure(0, weight=1)
# Crear widgets dentro del frame
top_frame = tk.Frame(main_frame, bg="blue")
top_frame.grid(row=0, column=0, sticky="nsew")
bottom_frame = tk.Frame(main_frame, bg="green")
bottom_frame.grid(row=1, column=0, sticky="nsew")
# Configurar tamaños responsivos en el frame principal
main_frame.grid_rowconfigure(0, weight=1)
main_frame.grid_rowconfigure(1, weight=1)
main_frame.grid_columnconfigure(0, weight=1)
# Ejecutar el bucle de la aplicación
root.mainloop()

101
graficos/ventanas.py Normal file
View File

@ -0,0 +1,101 @@
import tkinter as tk
from tkinter import messagebox
from tkinter import Menu
from ficheros import persistenciaFile
from bbdd import guardar
from scraping.busca import MiScraping
def option1():
cadena = "https://www.google.com"
guardar.guardar_enlace_en_bd(cadena)
MiObjScraping = MiScraping("https://ieslamar.org")
MiObjScraping.start()
MiObjScraping.join()
links = MiObjScraping.get_links()
for link in links:
text.insert(tk.END, link + "\n")
def option2():
messagebox.showinfo("Opción 2", "Has seleccionado la Opción 2")
def option3():
messagebox.showinfo("Opción 3", "Has seleccionado la Opción 3")
def option4():
messagebox.showinfo("Opción 4", "Has seleccionado la Opción 4")
# Crear la ventana principal de tamaño fijo
root = tk.Tk()
root.title("Menú de Opciones")
root.geometry("1000x500")
root.resizable(False, False)
# Crear el menú
menu_bar = tk.Menu(root)
# Agregar las opciones al menú
file_menu = Menu(menu_bar, tearoff=0)
file_menu.add_command(label="Nuevo")
file_menu.add_command(label="Abrir")
file_menu.add_separator()
file_menu.add_command(label="Salir", command=root.quit)
help_menu = Menu(menu_bar, tearoff=0)
help_menu.add_command(label="Acerca de")
menu_bar.add_cascade(label="Archivo", menu=file_menu)
menu_bar.add_cascade(label="Ayuda", menu=help_menu)
menu_bar.add_command(label="Scraping", command=option1)
menu_bar.add_command(label="Guardar enlaces", command=option2)
menu_bar.add_command(label="Guardar páginas", command=option3)
menu_bar.add_command(label="Contenido web", command=option4)
# Configurar la barra de menú en la ventana
root.config(menu=menu_bar)
# Pie de ventana
footer = tk.Label(root, text="Pie de ventana - Aquí puedes mostrar mensajes o estado", bd=1, relief=tk.SUNKEN, anchor="w")
footer.pack(side=tk.BOTTOM, fill=tk.X)
# Crear los frames principales
# frame top, alineación izquierda
frame_top = tk.Frame(root, bg="lightyellow", width=1000, height=50)
frame_left = tk.Frame(root, bg="lightblue", width=450, height=400)
frame_right = tk.Frame(root, bg="lightgreen", width=450, height=400)
frame_bottom = tk.Frame(root, bg="lightcoral", width=1000, height=50)
# Ubicar los frames en la ventana de forma absoluta
frame_top.pack(side="top")
frame_bottom.pack(side="bottom")
frame_left.pack(side="left")
frame_right.pack(side="left")
# Crear boton opcion 1 en frame1
button1 = tk.Button(frame_left, text="Scraping", command=option1)
button1.pack()
label = tk.Label(frame_bottom, text="Enlaces encontrados", bg=frame_bottom['bg'])
label.pack()
# crear un cuadro de texto de varias lineas
text = tk.Text(frame_left)
text.pack()
button2 = tk.Button(frame_right, text="Contenido", command=option4)
button2.pack()
contenido = tk.Text(frame_right)
contenido.pack()
# Iniciar el bucle principal de la aplicación
root.mainloop()

View File

@ -0,0 +1,152 @@
import tkinter as tk
from tkinter import Menu # Importar el widget Menu
from tkinter import ttk # Importar el widget ttk
import threading
import time
import datetime
def navega():
notebook.select(0)
#notebook.select(0).label(label_url.get().strip())
#notebook.select(0).update()
def update_time(status_bar):
"""Función que actualiza la hora y el día de la semana en un label"""
while True:
# Obtener la fecha y hora actual
now = datetime.datetime.now()
day_of_week = now.strftime("%A") # Día de la semana
time_str = now.strftime("%H:%M:%S") # Hora en formato HH:MM:SS
date_str = now.strftime("%Y-%m-%d") # Fecha en formato YYYY-MM-DD
label_text = f"{day_of_week}, {date_str} - {time_str}"
# Actualizar el label (debemos usar `after` para asegurarnos que se actualice en el hilo principal de Tkinter)
label_fecha_hora.after(1000, status_bar.config, {"text": label_text})
# Espera 1 segundo antes de actualizar de nuevo
time.sleep(1)
# Crear la ventana principal
root = tk.Tk()
root.title("Ventana Responsive")
root.geometry("1000x700") # Tamaño inicial
# Configurar la ventana principal para que sea responsive
root.columnconfigure(0, weight=0) # Columna izquierda, tamaño fijo
root.columnconfigure(1, weight=1) # Columna central, tamaño variable
root.columnconfigure(2, weight=0) # Columna derecha, tamaño fijo
root.rowconfigure(0, weight=1) # Fila principal, tamaño variable
root.rowconfigure(1, weight=0) # Barra de estado, tamaño fijo
# Crear el menú superior
menu_bar = Menu(root)
file_menu = Menu(menu_bar, tearoff=0)
file_menu.add_command(label="Nuevo")
file_menu.add_command(label="Abrir")
file_menu.add_separator()
file_menu.add_command(label="Salir", command=root.quit)
edit_menu = Menu(menu_bar, tearoff=0)
edit_menu.add_command(label="Copiar")
edit_menu.add_command(label="Pegar")
help_menu = Menu(menu_bar, tearoff=0)
help_menu.add_command(label="Acerca de")
menu_bar.add_cascade(label="Archivo", menu=file_menu)
menu_bar.add_cascade(label="Editar", menu=edit_menu)
menu_bar.add_cascade(label="Ayuda", menu=help_menu)
root.config(menu=menu_bar)
# Crear los frames laterales y el central
frame_izquierdo = tk.Frame(root, bg="lightblue", width=200)
frame_central = tk.Frame(root, bg="white")
frame_derecho = tk.Frame(root, bg="lightgreen", width=200)
# Colocar los frames laterales y el central
frame_izquierdo.grid(row=0, column=0, sticky="ns")
frame_central.grid(row=0, column=1, sticky="nsew")
frame_derecho.grid(row=0, column=2, sticky="ns")
# Configurar los tamaños fijos de los frames laterales
frame_izquierdo.grid_propagate(False)
frame_derecho.grid_propagate(False)
# Dividir el frame central en dos partes (superior variable e inferior fija)
frame_central.rowconfigure(0, weight=1) # Parte superior, tamaño variable
frame_central.rowconfigure(1, weight=0) # Parte inferior, tamaño fijo
frame_central.columnconfigure(0, weight=1) # Ocupa toda la anchura
# Crear subframes dentro del frame central
frame_superior = tk.Frame(frame_central, bg="lightyellow")
frame_inferior = tk.Frame(frame_central, bg="lightgray", height=100)
# Colocar los subframes dentro del frame central
frame_superior.grid(row=0, column=0, sticky="nsew")
frame_inferior.grid(row=1, column=0, sticky="ew")
# Fijar el tamaño de la parte inferior
frame_inferior.grid_propagate(False)
# Crear la barra de estado
barra_estado = tk.Label(root, text="Barra de estado", bg="lightgray", anchor="w")
barra_estado.grid(row=1, column=0, columnspan=3, sticky="ew")
# Notebook para las pestañas
style = ttk.Style()
style.configure("CustomNotebook.TNotebook.Tab", font=("Arial", 12, "bold"))
notebook = ttk.Notebook(frame_superior, style="CustomNotebook.TNotebook")
notebook.pack(fill="both", expand=True)
# Crear cinco solapas
for i in range(1, 6):
tab = ttk.Frame(notebook)
notebook.add(tab, text=f"Solapa {i}", padding=4)
# Añadir un Label en cada solapa para diferenciarla
label = ttk.Label(tab, text=f"Contenido de la Solapa {i}")
label.pack(pady=10)
# Barra de estado
# Dividir la barra de estado en 4 labels
# Usar pack para alinear los labels horizontalmente
label_1 = tk.Label(barra_estado, text="Estado 1", bg="green", anchor="w", width=20)
label_2 = tk.Label(barra_estado, text="Estado 2", bg="blue", anchor="w", width=20)
label_3 = tk.Label(barra_estado, text="Estado 3", bg="cyan", anchor="w", width=20)
label_4 = tk.Label(barra_estado, text="Estado 4", bg="pink", anchor="w", width=20)
label_fecha_hora = tk.Label(barra_estado, text="Hilo fecha-hora", font=("Helvetica", 14), bd=1, fg="blue", relief="sunken", anchor="w", width=20, padx=10)
label_1.pack(side="left", fill="x", expand=True)
label_2.pack(side="left", fill="x", expand=True)
label_3.pack(side="left", fill="x", expand=True)
label_4.pack(side="left", fill="x", expand=True)
label_fecha_hora.pack(side="right", fill="x", expand=True)
# barra_estado.grid(row=1, column=0, columnspan=3, sticky="ew")
label_url = tk.Label(frame_izquierdo,
text="Introduce URL:", font=("Arial", 12), padx=10, pady=10)
label_url.pack(pady=5)
text = tk.Text(frame_izquierdo, height=1, width=20)
text.pack(pady=5)
boton = tk.Button(frame_izquierdo, text="NAVEGAR", command=navega)
boton.pack(pady=5)
label_chat = tk.Label(frame_derecho,
text="C H A T", font=("Arial", 16), padx=10, pady=10)
label_chat.pack()
update_thread = threading.Thread(target=update_time, args=(label_fecha_hora,))
update_thread.daemon = True # Hacemos el hilo un demonio para que termine con la app
update_thread.start()
# Ejecución de la aplicación
root.mainloop()

View File

@ -0,0 +1,57 @@
import tkinter as tk
from tkinter import Menu
# Crear la ventana principal
root = tk.Tk()
root.title("Ventana Responsive")
root.geometry("800x600") # Tamaño inicial
# Configurar la ventana principal para que sea responsive
root.columnconfigure(0, weight=0) # Columna izquierda, tamaño fijo
root.columnconfigure(1, weight=1) # Columna central, tamaño variable
root.columnconfigure(2, weight=0) # Columna derecha, tamaño fijo
root.rowconfigure(0, weight=1) # Fila principal, tamaño variable
root.rowconfigure(1, weight=0) # Barra de estado, tamaño fijo
# Crear el menú superior
menu_bar = Menu(root)
file_menu = Menu(menu_bar, tearoff=0)
file_menu.add_command(label="Nuevo")
file_menu.add_command(label="Abrir")
file_menu.add_separator()
file_menu.add_command(label="Salir", command=root.quit)
edit_menu = Menu(menu_bar, tearoff=0)
edit_menu.add_command(label="Copiar")
edit_menu.add_command(label="Pegar")
help_menu = Menu(menu_bar, tearoff=0)
help_menu.add_command(label="Acerca de")
menu_bar.add_cascade(label="Archivo", menu=file_menu)
menu_bar.add_cascade(label="Editar", menu=edit_menu)
menu_bar.add_cascade(label="Ayuda", menu=help_menu)
root.config(menu=menu_bar)
# Crear los frames
frame_izquierdo = tk.Frame(root, bg="lightblue", width=300, height=600)
frame_central = tk.Frame(root, bg="white")
frame_derecho = tk.Frame(root, bg="lightgreen", width=300, height=600)
# Colocar los frames en el grid
frame_izquierdo.grid(row=0, column=0, sticky="ns")
frame_central.grid(row=0, column=1, sticky="nsew")
frame_derecho.grid(row=0, column=2, sticky="ns")
# Fijar tamaños de los frames laterales
frame_izquierdo.grid_propagate(False)
frame_derecho.grid_propagate(False)
# Crear la barra de estado
barra_estado = tk.Label(root, text="Barra de estado", bg="lightgray", anchor="w")
barra_estado.grid(row=1, column=0, columnspan=3, sticky="ew")
# Ejecución de la aplicación
root.mainloop()