Advertisement
Guest User

Sender

a guest
Mar 6th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. import Tkinter as tk
  2. import sys
  3. import os
  4. import socket
  5. import random
  6. import tkMessageBox
  7.  
  8. root= tk.Tk()
  9. root.title("UDP Messenger")
  10. w = 300
  11. h = 200
  12. x = 50
  13. y = 100
  14.  
  15. root.geometry("%dx%d+%d+%d" % (w, h, x, y))
  16. frame = tk.Frame(root, bg='white')
  17. frame.pack(fill='both', expand='yes')
  18.  
  19. ip1 = tk.Label(frame, font="Arial", text="IP: ")
  20. ip1.place(x=10, y=10)
  21.  
  22. ip2 = tk.Entry(frame, bd=5)
  23. ip2.place(x=60, y=10)
  24.  
  25. msg1 = tk.Label(frame, font="Arial",text="Message: ")
  26. msg1.place(x=10, y=50)
  27.  
  28. msg2 = tk.Entry(frame, bd=5, width=30)
  29. msg2.place(x=90, y=50)
  30.  
  31. def mail():
  32.     hostname = (ip2.get())
  33.     if hostname == "":
  34.         tkMessageBox.showinfo("Error", "IP Address is not defined")
  35.     msg3 = (msg2.get())
  36.     host = str(hostname)
  37.     msg = str(msg3)
  38.     s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  39.     s.sendto(msg, (host, 5005))
  40.    
  41. def quit():
  42.     sys.exit()
  43.    
  44. button = tk.Button(frame, text="Send", bg="yellow", font="Arial",width=10,command=mail)
  45. button.place(x=10, y=100)
  46.  
  47. button1 = tk.Button(frame, text="Quit", bg="red", font="Arial", fg="white", width=10,command=quit)
  48. button1.place(x=170, y=100)
  49.  
  50. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement