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