[英]How to label each circle you draw when using the method create_oval() from module tkinter?
[英]How to draw a circle on a label on Tkinter?
我試圖在其中有圖像的標簽上繪制一個圓(應該是鼠標光標)。 每次我將其插入插座時,都需要更改圓的位置,我在代碼中用**標記了鼠標的位置,我不知道該怎么做,如果您能幫助我,我將非常高興,非常感謝
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
方法更改光標本身。
但是,如果使用很小的畫布而不是標簽,則可以在添加到畫布上的文本上繪制。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.