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