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