2017-04-15 2 views
0

나는 그 안에 이미지가있는 레이블에 원 (마우스 커서라고 가정 함)을 그리려고했습니다. 소켓에 넣을 때마다 서클 위치를 바꿔야합니다. ** 내 코드에 **로 마우스를 올려 놓았습니다. 어떻게 해야할지 모르겠지만, 도와 주시면 기쁠 것입니다. 고마워요.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

구성 방법은 무엇입니까? 어떻게 그걸로 마우스를 그릴 수 있습니까? 나는 그가 마우스의 위치를 ​​잡을 때마다 마우스를 그릴 무언가를 만들 필요가있다. 스크린 공유 프로젝트의 일부가 될 필요가있다. –