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