Project

General

Profile

Codigo Utilizado » History » Version 1

Version 1/7 - Next » - Current version
israel tebes, 10/16/2024 03:38 PM


Codigo Utilizado

INTERFAZ
[[import tkinter as tk
from tkinter import *
from tkinter import messagebox
from tkinter import ttk
import socket

def adelante():
clientSocket.send(bytes([ord('w')]))

def atras():
clientSocket.send(bytes([ord('s')]))

def derecha():
clientSocket.send(bytes([ord('d')]))

def izquierda():
clientSocket.send(bytes([ord('a')]))

def Subir():
clientSocket.send(bytes([ord('o')]))

def Bajar():
clientSocket.send(bytes([ord('i')]))

def Agarrar():
clientSocket.send(bytes([ord('k')]))

def Soltar():
clientSocket.send(bytes([ord('l')]))

def on_release(event):
clientSocket.send(bytes([ord(' ')]))

def get_ip():
ventana_ip = Tk()
ventana_ip.geometry("300x100")
ventana_ip.resizable(0,0)

ip = StringVar(ventana_ip)
ventana_ip.title("Configurar Ip")
ip_label = Label(ventana_ip, text="Ingresar Ip:").place(x=10,y=10)
ip_entry = ttk.Entry(ventana_ip,textvariable=ip).place(x=80,y=10)
button = Button(ventana_ip,text =" Aplicar",command=lambda:[conectar(ip.get(),port),ventana_ip.destroy()]).place(x=140,y=60)
print(ip.get())

def conectar(adress,port):
try:
clientSocket.connect((adress,port))
messagebox.showinfo("Mensaje Servido","Cliente conectado al robot: {0} : {1}".format(adress,port))
except socket.error:
messagebox.showwarning("Conexión erronea","No se ha logrado al conexión, verifique la Ip {0}".format(adress))
get_ip()
clientSocket.close()

#Ventana
ventana = Tk()
ventana.geometry("500x500")
ventana.title("hola")
ventana.resizable(0,0)

boton_adelante = Button(ventana, text= "Adelante",repeatdelay=50,repeatinterval=50,command=adelante)
boton_adelante.bind('<ButtonRelease-1>',on_release)
boton_adelante.place(x=70,y=20)

boton_atras = Button(ventana, text= "Atrás",repeatdelay=50,repeatinterval=50,command=atras)
boton_atras.bind('<ButtonRelease-1>',on_release)
boton_atras.place(x=80,y=170)

boton_der = Button(ventana,text= "Derecha",repeatdelay=50,repeatinterval=50,command=derecha)
boton_der.bind('<ButtonRelease-1>',on_release)
boton_der.place(x=140,y=90)

boton_izq = Button(ventana, text = "Izquierda",repeatdelay=50,repeatinterval=50,command=izquierda)
boton_izq.bind('<ButtonRelease-1>',on_release)
boton_izq.place(x=5,y=90)

boton_subir = tk.Button(ventana,text = "Subir",command=Subir)
boton_subir.bind('<ButtonRelease-1>',on_release)
boton_subir.place(x=0,y=0)

boton_bajar = tk.Button(ventana,text = "Abajar",command=Bajar)
boton_bajar.bind('<ButtonRelease-1>',on_release)
boton_bajar.place(x=100,y=0)

boton_agarrar = tk.Button(ventana,text = "Agarrar",command=Agarrar)
boton_agarrar.bind('<ButtonRelease-1>',on_release)
boton_agarrar.place(x=200,y=0)

boton_soltar = tk.Button(ventana,text = "Soltar",command=Soltar)
boton_soltar.bind('<ButtonRelease-1>',on_release)
boton_soltar.place(x=300,y=0)

boton_conectar = Button(ventana,text="Conectar",command=lambda:[get_ip()]).place(x=70,y=82)

clientSocket = socket.socket()
port = 8080

ventana.mainloop()
]]