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