Project

General

Profile

Interfaz » History » Version 5

cristobal hernandez, 09/10/2024 05:32 PM

1 1 ana gutierrez
h1. Interfaz
2 4 cristobal hernandez
3 5 cristobal hernandez
<pre><code class="python">
4 5 cristobal hernandez
import tkinter as tk
5 5 cristobal hernandez
6 5 cristobal hernandez
class Aplicacion:
7 5 cristobal hernandez
    def __init__(self, root):
8 5 cristobal hernandez
        self.root = root
9 5 cristobal hernandez
        self.root.title("Blitz")
10 5 cristobal hernandez
        self.root.geometry("800x450")
11 5 cristobal hernandez
        self.root.resizable(0, 0)
12 5 cristobal hernandez
13 5 cristobal hernandez
        # Cargar el logo
14 5 cristobal hernandez
        self.root.iconbitmap("resources/logo.ico")
15 5 cristobal hernandez
16 5 cristobal hernandez
        # Cargar la imagen de fondo
17 5 cristobal hernandez
        self.imagen_fondo = tk.PhotoImage(file="resources/fondo1.png")
18 5 cristobal hernandez
        
19 5 cristobal hernandez
        # Crear un Canvas para colocar la imagen de fondo
20 5 cristobal hernandez
        self.canvas = tk.Canvas(self.root, width=800, height=400)
21 5 cristobal hernandez
        self.canvas.pack(fill="both", expand=True)
22 5 cristobal hernandez
23 5 cristobal hernandez
        # Colocar la imagen en el Canvas
24 5 cristobal hernandez
        self.canvas.create_image(0, 0, image=self.imagen_fondo, anchor="nw")
25 5 cristobal hernandez
        
26 5 cristobal hernandez
        # Imágenes para los botones
27 5 cristobal hernandez
        self.imagen_central = tk.PhotoImage(file="resources/center.png")
28 5 cristobal hernandez
        self.imagen_arriba = tk.PhotoImage(file="resources/up.png")
29 5 cristobal hernandez
        self.imagen_abajo = tk.PhotoImage(file="resources/down.png")
30 5 cristobal hernandez
        self.imagen_izquierda = tk.PhotoImage(file="resources/left.png")
31 5 cristobal hernandez
        self.imagen_derecha = tk.PhotoImage(file="resources/right.png")
32 5 cristobal hernandez
        self.imagen_apagado = tk.PhotoImage(file="resources/off.png")
33 5 cristobal hernandez
34 5 cristobal hernandez
        
35 5 cristobal hernandez
        # Cuadro "transparente"
36 5 cristobal hernandez
        self.canvas.create_rectangle(50, 210, 230, 390, fill="#052D45", stipple="gray50", outline="")
37 5 cristobal hernandez
        
38 5 cristobal hernandez
        self.crear_botones()
39 5 cristobal hernandez
40 5 cristobal hernandez
    def crear_botones(self):
41 5 cristobal hernandez
        self.boton_central = tk.Button(self.root, image=self.imagen_central, borderwidth=0, highlightthickness=0, cursor="hand2")
42 5 cristobal hernandez
        self.canvas.create_window(140, 300, window=self.boton_central)
43 5 cristobal hernandez
        
44 5 cristobal hernandez
        self.boton_arriba = tk.Button(self.root, image=self.imagen_arriba, borderwidth=0, highlightthickness=0, cursor="hand2")
45 5 cristobal hernandez
        self.canvas.create_window(140, 245, window=self.boton_arriba)
46 5 cristobal hernandez
        
47 5 cristobal hernandez
        self.boton_abajo = tk.Button(self.root, image=self.imagen_abajo, borderwidth=0, highlightthickness=0, cursor="hand2")
48 5 cristobal hernandez
        self.canvas.create_window(140, 355, window=self.boton_abajo)
49 5 cristobal hernandez
        
50 5 cristobal hernandez
        self.boton_izquierda = tk.Button(self.root, image=self.imagen_izquierda, borderwidth=0, highlightthickness=0, cursor="hand2")
51 5 cristobal hernandez
        self.canvas.create_window(85, 300, window=self.boton_izquierda)
52 5 cristobal hernandez
        
53 5 cristobal hernandez
        self.boton_derecha = tk.Button(self.root, image=self.imagen_derecha, borderwidth=0, highlightthickness=0, cursor="hand2")
54 5 cristobal hernandez
        self.canvas.create_window(195, 300, window=self.boton_derecha)
55 5 cristobal hernandez
56 5 cristobal hernandez
        self.boton_apagado = tk.Button(self.root, image=self.imagen_apagado, borderwidth=0, highlightthickness=0, cursor="hand2")
57 5 cristobal hernandez
        self.canvas.create_window(755, 400, window=self.boton_apagado)
58 5 cristobal hernandez
59 5 cristobal hernandez
if __name__ == "__main__":
60 5 cristobal hernandez
    root = tk.Tk()
61 5 cristobal hernandez
    app = Aplicacion(root)
62 5 cristobal hernandez
    root.mainloop()
63 4 cristobal hernandez
</code></pre>