如何在Tkinter上的标签上画圆圈?

时间:2017-04-15 14:49:00

标签: python sockets tkinter label

我试图在其中包含图像的标签上绘制一个圆圈(它应该是一个鼠标光标)。 每次我在套接字上得到它时,需要改变圆形位置 我注意到我的代码上有**的鼠标poisition 我不知道怎么做,如果你帮助我,我会很高兴的, 非常感谢

        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()

1 个答案:

答案 0 :(得分:0)

您无法在已有图像的标签上绘制图像。您可以使用configure方法更改光标本身。

但是,如果使用非常小的画布而不是标签,则可以在添加到画布的文本上绘制。