Codigo Utilizado » History » Version 6
israel tebes, 10/16/2024 03:44 PM
| 1 | 1 | israel tebes | h1. Codigo Utilizado |
|---|---|---|---|
| 2 | 1 | israel tebes | |
| 3 | 6 | israel tebes | *INTERFAZ* |
| 4 | 5 | israel tebes | |
| 5 | 5 | israel tebes | <pre> |
| 6 | 5 | israel tebes | import tkinter as tk |
| 7 | 5 | israel tebes | from tkinter import * |
| 8 | 5 | israel tebes | from tkinter import messagebox |
| 9 | 5 | israel tebes | from tkinter import ttk |
| 10 | 5 | israel tebes | import socket |
| 11 | 5 | israel tebes | |
| 12 | 5 | israel tebes | def adelante(): |
| 13 | 5 | israel tebes | clientSocket.send(bytes([ord('w')])) |
| 14 | 5 | israel tebes | |
| 15 | 5 | israel tebes | def atras(): |
| 16 | 5 | israel tebes | clientSocket.send(bytes([ord('s')])) |
| 17 | 5 | israel tebes | |
| 18 | 5 | israel tebes | def derecha(): |
| 19 | 5 | israel tebes | clientSocket.send(bytes([ord('d')])) |
| 20 | 5 | israel tebes | |
| 21 | 5 | israel tebes | def izquierda(): |
| 22 | 5 | israel tebes | clientSocket.send(bytes([ord('a')])) |
| 23 | 5 | israel tebes | |
| 24 | 5 | israel tebes | def Subir(): |
| 25 | 5 | israel tebes | clientSocket.send(bytes([ord('o')])) |
| 26 | 5 | israel tebes | |
| 27 | 5 | israel tebes | def Bajar(): |
| 28 | 5 | israel tebes | clientSocket.send(bytes([ord('i')])) |
| 29 | 5 | israel tebes | |
| 30 | 5 | israel tebes | def Agarrar(): |
| 31 | 5 | israel tebes | clientSocket.send(bytes([ord('k')])) |
| 32 | 5 | israel tebes | |
| 33 | 5 | israel tebes | def Soltar(): |
| 34 | 5 | israel tebes | clientSocket.send(bytes([ord('l')])) |
| 35 | 5 | israel tebes | |
| 36 | 5 | israel tebes | def on_release(event): |
| 37 | 5 | israel tebes | clientSocket.send(bytes([ord(' ')])) |
| 38 | 5 | israel tebes | |
| 39 | 5 | israel tebes | def get_ip(): |
| 40 | 5 | israel tebes | ventana_ip = Tk() |
| 41 | 5 | israel tebes | ventana_ip.geometry("300x100") |
| 42 | 5 | israel tebes | ventana_ip.resizable(0,0) |
| 43 | 5 | israel tebes | |
| 44 | 5 | israel tebes | ip = StringVar(ventana_ip) |
| 45 | 5 | israel tebes | ventana_ip.title("Configurar Ip") |
| 46 | 5 | israel tebes | ip_label = Label(ventana_ip, text="Ingresar Ip:").place(x=10,y=10) |
| 47 | 5 | israel tebes | ip_entry = ttk.Entry(ventana_ip,textvariable=ip).place(x=80,y=10) |
| 48 | 5 | israel tebes | button = Button(ventana_ip,text =" Aplicar",command=lambda:[conectar(ip.get(),port),ventana_ip.destroy()]).place(x=140,y=60) |
| 49 | 5 | israel tebes | |
| 50 | 5 | israel tebes | print(ip.get()) |
| 51 | 5 | israel tebes | |
| 52 | 5 | israel tebes | def conectar(adress,port): |
| 53 | 5 | israel tebes | try: |
| 54 | 5 | israel tebes | clientSocket.connect((adress,port)) |
| 55 | 5 | israel tebes | messagebox.showinfo("Mensaje Servido","Cliente conectado al robot: {0} : {1}".format(adress,port)) |
| 56 | 5 | israel tebes | except socket.error: |
| 57 | 5 | israel tebes | messagebox.showwarning("Conexión erronea","No se ha logrado al conexión, verifique la Ip {0}".format(adress)) |
| 58 | 5 | israel tebes | get_ip() |
| 59 | 5 | israel tebes | clientSocket.close() |
| 60 | 5 | israel tebes | |
| 61 | 5 | israel tebes | #Ventana |
| 62 | 5 | israel tebes | ventana = Tk() |
| 63 | 5 | israel tebes | ventana.geometry("500x500") |
| 64 | 5 | israel tebes | ventana.title("hola") |
| 65 | 5 | israel tebes | ventana.resizable(0,0) |
| 66 | 5 | israel tebes | |
| 67 | 5 | israel tebes | boton_adelante = Button(ventana, text= "Adelante",repeatdelay=50,repeatinterval=50,command=adelante) |
| 68 | 5 | israel tebes | boton_adelante.bind('<ButtonRelease-1>',on_release) |
| 69 | 5 | israel tebes | boton_adelante.place(x=70,y=20) |
| 70 | 5 | israel tebes | |
| 71 | 5 | israel tebes | boton_atras = Button(ventana, text= "Atrás",repeatdelay=50,repeatinterval=50,command=atras) |
| 72 | 5 | israel tebes | boton_atras.bind('<ButtonRelease-1>',on_release) |
| 73 | 5 | israel tebes | boton_atras.place(x=80,y=170) |
| 74 | 5 | israel tebes | |
| 75 | 5 | israel tebes | boton_der = Button(ventana,text= "Derecha",repeatdelay=50,repeatinterval=50,command=derecha) |
| 76 | 5 | israel tebes | boton_der.bind('<ButtonRelease-1>',on_release) |
| 77 | 5 | israel tebes | boton_der.place(x=140,y=90) |
| 78 | 5 | israel tebes | |
| 79 | 5 | israel tebes | boton_izq = Button(ventana, text = "Izquierda",repeatdelay=50,repeatinterval=50,command=izquierda) |
| 80 | 5 | israel tebes | boton_izq.bind('<ButtonRelease-1>',on_release) |
| 81 | 5 | israel tebes | boton_izq.place(x=5,y=90) |
| 82 | 5 | israel tebes | |
| 83 | 5 | israel tebes | boton_subir = tk.Button(ventana,text = "Subir",command=Subir) |
| 84 | 5 | israel tebes | boton_subir.bind('<ButtonRelease-1>',on_release) |
| 85 | 5 | israel tebes | boton_subir.place(x=0,y=0) |
| 86 | 5 | israel tebes | |
| 87 | 5 | israel tebes | boton_bajar = tk.Button(ventana,text = "Abajar",command=Bajar) |
| 88 | 5 | israel tebes | boton_bajar.bind('<ButtonRelease-1>',on_release) |
| 89 | 5 | israel tebes | boton_bajar.place(x=100,y=0) |
| 90 | 5 | israel tebes | |
| 91 | 5 | israel tebes | boton_agarrar = tk.Button(ventana,text = "Agarrar",command=Agarrar) |
| 92 | 5 | israel tebes | boton_agarrar.bind('<ButtonRelease-1>',on_release) |
| 93 | 5 | israel tebes | boton_agarrar.place(x=200,y=0) |
| 94 | 5 | israel tebes | |
| 95 | 5 | israel tebes | boton_soltar = tk.Button(ventana,text = "Soltar",command=Soltar) |
| 96 | 5 | israel tebes | boton_soltar.bind('<ButtonRelease-1>',on_release) |
| 97 | 5 | israel tebes | boton_soltar.place(x=300,y=0) |
| 98 | 5 | israel tebes | |
| 99 | 5 | israel tebes | boton_conectar = Button(ventana,text="Conectar",command=lambda:[get_ip()]).place(x=70,y=82) |
| 100 | 5 | israel tebes | |
| 101 | 5 | israel tebes | |
| 102 | 5 | israel tebes | clientSocket = socket.socket() |
| 103 | 5 | israel tebes | port = 8080 |
| 104 | 5 | israel tebes | |
| 105 | 5 | israel tebes | ventana.mainloop() |
| 106 | 5 | israel tebes | |
| 107 | 5 | israel tebes | </pre> |