2017-04-15 49 views
0

我試圖畫一個圓圈(它應該是一個鼠標光標)在其中有圖像的標籤上。 圓圈的位置需要改變,每次我得到它在插座上 我注意到了我的代碼**上的鼠標POULDER 我不知道該怎麼做,我會很高興,如果你幫我, 非常感謝如何在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() 

回答

0

您不能在已有圖像的標籤上繪製圖像。您可以使用configure方法更改光標本身。

但是,如果使用非常小的畫布而不是標籤,則可以在添加到畫布上的文本頂部繪製。

+0

什麼是配置方法?我如何繪製鼠標?我需要構建一些能夠在每次獲得位置時繪製鼠標的東西,它需要成爲屏幕共享項目的一部分 –