import socket import pyautogui import os import tkinter as tk root = tk.Tk() canvas1 = tk.Canvas(root, width = 600, height = 300) canvas1.pack() s = socket.socket() s.connect(("localhost", 5000)) def takeScreenShot(): myscreenshot = pyautogui.screenshot() #save_path = tk.filedialog.asksaveasfilename() myscreenshot.save("pic1.jpg") filetosend = open("pic1.jpg", "rb") data = filetosend.read(1024) while data: s.send(data) data = filetosend.read(1024) filetosend.close() #"Send DONE." s.send(b"DONE") #to break while print("Done Sending.") os.remove("pic1.jpg") #delete picture in sever s.shutdown(2) s.close() myButton = tk.Button(text = "Take ScreenShot", command = takeScreenShot, font = 12) canvas1.create_window(150, 150, window = myButton) root.mainloop()