tkinter 用鼠标在任何方向创建矩形
tkinter create rect with mouse in any direction
有什么方法可以在 tkinter canvas 上通过单击鼠标从右上边缘到左下边缘绘制矩形(与传统方式不同)?
这是参考creating rect with mouse drag
def on_button_press(self, event):
# save mouse drag start position
self.start_x = event.x
self.start_y = event.y
# create rectangle if not yet exist
#if not self.rect:
self.rect = self.canvas.create_rectangle(self.x, self.y, 1, 1, fill="black")
def on_move_press(self, event):
curX, curY = (event.x, event.y)
# expand rectangle as you drag the mouse
self.canvas.coords(self.rect, self.start_x, self.start_y, curX, curY)
def on_button_release(self, event):
pass
感谢 acw1668
这条线是完美的解决方案
self.rect = self.canvas.create_rectangle(self.start_x, self.start_y, self.start_x, self.start_y, fill="black")
有什么方法可以在 tkinter canvas 上通过单击鼠标从右上边缘到左下边缘绘制矩形(与传统方式不同)? 这是参考creating rect with mouse drag
def on_button_press(self, event):
# save mouse drag start position
self.start_x = event.x
self.start_y = event.y
# create rectangle if not yet exist
#if not self.rect:
self.rect = self.canvas.create_rectangle(self.x, self.y, 1, 1, fill="black")
def on_move_press(self, event):
curX, curY = (event.x, event.y)
# expand rectangle as you drag the mouse
self.canvas.coords(self.rect, self.start_x, self.start_y, curX, curY)
def on_button_release(self, event):
pass
感谢 acw1668 这条线是完美的解决方案
self.rect = self.canvas.create_rectangle(self.start_x, self.start_y, self.start_x, self.start_y, fill="black")