2010-07-17 2 views
3

위젯에 드래그 앤 드롭 기능을 만들고 싶습니다. 코드는 다음과 같습니다.tkinter : 위젯 드래그

from tkinter import * 


root = Tk() 
root.config(background = "red", width = 500, height = 500) 
root.title("root") 

def frameDrag(event): 
    frame.place(x = event.x , y = event.y) 

frame = Frame(root, width = 60, height = 30) 
frame.place(x=0, y=0) 
frame.bind("<B1-Motion>", frameDrag) 

root.mainloop() 

기본적으로 마우스를 움직이는 위치에 위젯을 배치해야합니다. 대신, 창 부품 위젯 주위 점프. 이 문제를 해결하는 방법에 대한 아이디어가 있으십니까? 당신이 같이 그것을 말하고 있기 때문에

답변

1

그것은 여기 저기를 뛰어 :

def frameDrag(event): 
    print event.x, event.y 
    frame.place(x = event.x , y = event.y) 

더 나은 캔버스 위젯을 사용하고 더 나은 사용하는 B1을 클릭하고 B1-출시 이벤트를하고 델타를 계산 . Tkinter와 함께 제공되는 위젯 데모를 찾으십시오.