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