python - Tkinter: How to move widgets on canvas? -


im tryin app move every widget on canvas. first step moved rectangle, want move widget! thought "it same thing!" im wrong :( here code:

from tkinter import *  clicked = false  def callback(event):     global clicked, start, pre_x,pre_y      if clicked:         clicked = false      else:         if event.x >= canvas.coords(rec)[0] , event.x <= canvas.coords(rec)[2] , event.y >= canvas.coords(rec)[1] , event.y <=canvas.coords(rec)[3]:             clicked = true             canvas.itemconfig(rec,fill = "blue")             pre_x = event.x             pre_y = event.y             canvas.bind("<b1-motion>",movement)  def movement(event):     global clicked, start, pre_x,pre_y      if clicked:         x_diff = event.x - pre_x         y_diff = event.y - pre_y         #print("reccoord[1]=" + str(canvas.coords(rec)[1]))         pre_x = event.x         pre_y = event.y         #print("reccoord[1] = " + str(canvas.coords(rec)[1]))         canvas.move(rec,x_diff,y_diff)  window = tk() w = window.winfo_screenwidth() h = window.winfo_screenheight() window.geometry('%dx%d+0+0' % (w, h)) window.title('finestra di disegno') canvas = canvas(window, width = w, height = h) rec = canvas.create_rectangle(100,100, 100 + 55,100 + 26) canvas.pack() tmpbutton = button(window, text = "click me!") tmpbutton.pack() tmpbutton.update()  canvas.create_window(100,100, window = tmpbutton, anchor = nw, tags = 'button') canvas.bind("<button-1>",callback) tmpbutton.bind("<button-1>",callback) window.mainloop() 

my idea create rectangle under button widget, when move rectangle can refresh button coords new coords of rectangle! canvas don't capture event on widget, because every widget have event handler, right? bind button widget too, without result!! can me?? repeat question, need move widget on canvas rectangle... lot :d


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -