0
私はそれに画像を有するラベルに(そのマウスカーソルことになって)円を描画しようとしました。 円の位置をソケット上に置くたびに変更する必要があります 私のコードに**と書かれたマウスの表示 どうすればいいのかわかりません、助けてくれれば嬉しいです ありがとう?
import socket
from PIL import Image
import StringIO
import Tkinter
from PIL import Image
from PIL import ImageTk
import threading
RECV_BLOCK=1024
s=socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.connect(("127.0.0.1",12345))
im = None
def ShowImage():
root = Tkinter.Tk()
label = Tkinter.Label(root)
label.pack()
img = None
tkimg = [None] # This, or something like it, is necessary because if you do not keep a reference to PhotoImage instances, they get garbage collected.
delay = 2 # in milliseconds
def loopCapture():
print "capturing"
# img = fetch_image(URL,USERNAME,PASSWORD)
global im
while im==None:
continue
img = im
tkimg[0] = ImageTk.PhotoImage(img)
label.config(image=tkimg[0])
root.update_idletasks()
root.after(delay, loopCapture)
loopCapture()
root.mainloop()
def rcvimage():
global im
for i in range(1000):
data=''
size=s.recv(RECV_BLOCK)
s.send(size)
size=int(size)
while True:
buf=s.recv(RECV_BLOCK)
data+=buf
if len(data)>=size:
break
pic =data[:data.find("$$$$$$")]
mouse=data[data.find("$$$$$$")+6:] # **the position of the cursor is here - for example ("125$200") - the first number is x, and the second is y**
print mouse
try:
print(len(pic))
f=StringIO.StringIO(pic)
global im
im=Image.open(f)
#ShowImage(im)
#im.show()
s.send ("next")
except Exception as e:
s.send("fail:"+e.message)
break
print "End"
thread2 = threading.Thread(target = rcvimage)
thread1 = threading.Thread(target = ShowImage)
thread1.start()
thread2.start()
configureメソッドは何ですか?どのように私はそれでマウスを描くことができますか?私は彼がそれの位置を取得するたびに、マウスを描画します何かを構築する必要があり、その必要性は、画面共有プロジェクトの一部であることを –