Project

General

Profile

Código de la interfaz » History » Version 1

Ruben Salas, 01/03/2024 10:28 PM

1 1 Ruben Salas
h1. Código de la interfaz
2 1 Ruben Salas
3 1 Ruben Salas
<pre>
4 1 Ruben Salas
from tkinter import * 
5 1 Ruben Salas
from tkinter import messagebox
6 1 Ruben Salas
from tkinter import ttk
7 1 Ruben Salas
import socket
8 1 Ruben Salas
import time 
9 1 Ruben Salas
import sys
10 1 Ruben Salas
11 1 Ruben Salas
# Funciones ------------------------------------
12 1 Ruben Salas
def up(event = None):
13 1 Ruben Salas
    clientSocket.send(bytes([ord('w')]))
14 1 Ruben Salas
15 1 Ruben Salas
def down(event = None):
16 1 Ruben Salas
    clientSocket.send(bytes([ord('s')]))
17 1 Ruben Salas
18 1 Ruben Salas
def left(event = None):
19 1 Ruben Salas
    clientSocket.send(bytes([ord('a')]))
20 1 Ruben Salas
21 1 Ruben Salas
def right(event = None):
22 1 Ruben Salas
    clientSocket.send(bytes([ord('d')]))
23 1 Ruben Salas
24 1 Ruben Salas
def StrongArm(event = None):
25 1 Ruben Salas
    clientSocket.send(bytes([ord('f')]))
26 1 Ruben Salas
27 1 Ruben Salas
def WeakArm(event = None):
28 1 Ruben Salas
    clientSocket.send(bytes([ord('p')]))
29 1 Ruben Salas
30 1 Ruben Salas
def BackArm(event = None):
31 1 Ruben Salas
    clientSocket.send(bytes([ord('i')]))
32 1 Ruben Salas
33 1 Ruben Salas
def on_realese(event):
34 1 Ruben Salas
    print("click realese")
35 1 Ruben Salas
    clientSocket.send(bytes([ord(' ')]))
36 1 Ruben Salas
37 1 Ruben Salas
def getAddres():
38 1 Ruben Salas
    w_ip = Tk() 
39 1 Ruben Salas
    w_ip.geometry("300x100")
40 1 Ruben Salas
    w_ip.resizable(False, False)
41 1 Ruben Salas
    w_ip.grab_set()
42 1 Ruben Salas
    dato = StringVar(w_ip)
43 1 Ruben Salas
    w_ip.title("Ingrese dirección IP")
44 1 Ruben Salas
    ip = ttk.Entry(w_ip,textvariable=dato).place(x=10,y=10)
45 1 Ruben Salas
    button = Button(w_ip,text = "Conectar",command=lambda:[conectar(dato.get()),w_ip.destroy()]).place(x=170,y=9)
46 1 Ruben Salas
    print(dato.get())
47 1 Ruben Salas
48 1 Ruben Salas
def conectar(adress):
49 1 Ruben Salas
	port = 19999
50 1 Ruben Salas
	try:
51 1 Ruben Salas
		clientSocket.connect((adress,port))
52 1 Ruben Salas
		messagebox.showinfo("Mensaje Servido","Cliente conectado al robot: {0} : {1}".format(adress,port))
53 1 Ruben Salas
	except socket.error:
54 1 Ruben Salas
		messagebox.showwarning("Conexión erronea","No se ha logrado al conexíon, verifique la Ip {0}".format(adress))
55 1 Ruben Salas
		clientSocket.close()
56 1 Ruben Salas
          
57 1 Ruben Salas
# -------------------------------------------------
58 1 Ruben Salas
59 1 Ruben Salas
window = Tk()
60 1 Ruben Salas
window.geometry("600x500")
61 1 Ruben Salas
window.resizable(False, False)
62 1 Ruben Salas
63 1 Ruben Salas
# Imágenes ----------------------------------------
64 1 Ruben Salas
65 1 Ruben Salas
Arriba = PhotoImage(file="icono.gif")
66 1 Ruben Salas
Abajo = PhotoImage(file="iconoabajo.gif")
67 1 Ruben Salas
Derecha = PhotoImage(file="iconoderecha.gif")
68 1 Ruben Salas
Izquierda = PhotoImage(file="iconoizquierda.gif")
69 1 Ruben Salas
Fondo = PhotoImage(file="fondo.gif")
70 1 Ruben Salas
Wifi = PhotoImage(file="wifi.gif")
71 1 Ruben Salas
Mas_Rapido = PhotoImage(file="muyrapido.gif")
72 1 Ruben Salas
Rapido = PhotoImage(file="rapido.gif")
73 1 Ruben Salas
Logo = PhotoImage(file="LogoGolf2.png")
74 1 Ruben Salas
Atras = PhotoImage(file="rapido2.png")
75 1 Ruben Salas
Apagar = PhotoImage(file="Apagar.gif")
76 1 Ruben Salas
77 1 Ruben Salas
#--------------------------------------------------
78 1 Ruben Salas
79 1 Ruben Salas
fondo = Label(window, width=1500, height=1000, image=Fondo)
80 1 Ruben Salas
fondo.pack()
81 1 Ruben Salas
82 1 Ruben Salas
Golf = Label(window, width=200, height=40, image=Logo, bg="blue4").place(x=200,y=100)
83 1 Ruben Salas
84 1 Ruben Salas
# Botón Avanzar
85 1 Ruben Salas
boton_avanzar = Button(window, repeatdelay = 50, repeatinterval = 50, image = Arriba,
86 1 Ruben Salas
                       command = up, height = 50, width = 60,bg = "blue4")
87 1 Ruben Salas
boton_avanzar.place(x=90,y=140)
88 1 Ruben Salas
boton_avanzar.bind('<ButtonRelease-1>',on_realese)
89 1 Ruben Salas
90 1 Ruben Salas
# Botón Retroceder
91 1 Ruben Salas
boton_retroceder = Button(window, repeatdelay = 50, repeatinterval = 50,image = Abajo,
92 1 Ruben Salas
                          command = down, height = 50, width = 60,bg = "blue4")
93 1 Ruben Salas
boton_retroceder.place(x=90,y=260)
94 1 Ruben Salas
boton_retroceder.bind('<ButtonRelease-1>',on_realese)
95 1 Ruben Salas
96 1 Ruben Salas
# Botón derecha
97 1 Ruben Salas
boton_derecha = Button(window, repeatdelay = 50, repeatinterval = 50,image = Derecha,
98 1 Ruben Salas
                       command = right, height = 50, width = 60, bg = "blue4")
99 1 Ruben Salas
boton_derecha.place(x=160,y=200)
100 1 Ruben Salas
boton_derecha.bind('<ButtonRelease-1>',on_realese)
101 1 Ruben Salas
102 1 Ruben Salas
# Botón Izquierda
103 1 Ruben Salas
boton_izquierda = Button(window, repeatdelay = 50, repeatinterval = 50, image = Izquierda,
104 1 Ruben Salas
                         command = left, height = 50, width = 60, bg = "blue4")
105 1 Ruben Salas
boton_izquierda.place(x=20,y=200)
106 1 Ruben Salas
boton_izquierda.bind('<ButtonRelease-1>',on_realese)
107 1 Ruben Salas
108 1 Ruben Salas
# Botón Lanzar
109 1 Ruben Salas
boton_lanzar = Button(window, repeatdelay = 50, repeatinterval = 50, image = Rapido,
110 1 Ruben Salas
                      command = WeakArm, height = 50, width = 60, bg = "blue4")
111 1 Ruben Salas
boton_lanzar.place(x=440,y=230)
112 1 Ruben Salas
boton_lanzar.bind('<ButtonRelease-1>',on_realese)
113 1 Ruben Salas
114 1 Ruben Salas
# Botón Lanzamiento Fuerte
115 1 Ruben Salas
boton_lanzarF = Button(window,repeatdelay = 50, repeatinterval = 50, image= Mas_Rapido,
116 1 Ruben Salas
                       command = StrongArm, height = 50, width = 60, bg = "blue4")
117 1 Ruben Salas
boton_lanzarF.place(x=480,y=160)
118 1 Ruben Salas
boton_lanzarF.bind('<ButtonRelease-1>',on_realese)
119 1 Ruben Salas
120 1 Ruben Salas
# Botón Retroceder Brazo
121 1 Ruben Salas
boton_lanzarA = Button(window,repeatdelay = 50, repeatinterval = 50, image = Atras,
122 1 Ruben Salas
                       command = BackArm, height = 50, width = 60, bg = "blue4")
123 1 Ruben Salas
boton_lanzarA.place(x=400,y=160)
124 1 Ruben Salas
boton_lanzarA.bind('<ButtonRelease-1>',on_realese)
125 1 Ruben Salas
126 1 Ruben Salas
# Botón Cerrar
127 1 Ruben Salas
boton_cerrar = Button(window,image= Apagar, command = window.destroy, height = 50, width = 60, 
128 1 Ruben Salas
                      bg = "blue4").place(x=350,y=350)
129 1 Ruben Salas
130 1 Ruben Salas
# Botón Conectar
131 1 Ruben Salas
boton_conectar = Button(window,image = Wifi, command = getAddres, height = 50,width = 60, bg = "blue4").place(x=250,y=350)
132 1 Ruben Salas
133 1 Ruben Salas
clientSocket = socket.socket()
134 1 Ruben Salas
port = 1999
135 1 Ruben Salas
ipAddress = ""
136 1 Ruben Salas
137 1 Ruben Salas
window.mainloop()
138 1 Ruben Salas
</pre>