本文整理汇总了Python中tkinter.Canvas.find_closest方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.find_closest方法的具体用法?Python Canvas.find_closest怎么用?Python Canvas.find_closest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Canvas
的用法示例。
在下文中一共展示了Canvas.find_closest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from tkinter import Canvas [as 别名]
# 或者: from tkinter.Canvas import find_closest [as 别名]
#.........这里部分代码省略.........
def unproject(self, point):
return point.rotate(0, -self.phi).rotate(-self.theta, 0)
def move_camera(self, theta, phi):
self.theta += theta
if self.theta > 2 * math.pi:
self.theta -= 2 * math.pi
elif self.theta < 0:
self.theta += 2 * math.pi
if -math.pi / 2 <= self.phi + phi <= math.pi / 2:
self.phi += phi
def clear(self):
for item in self.items:
self.canvas.delete(item)
def draw_line(self, owner, p1, p2, **kargs):
assert isinstance(p1, Point3)
assert isinstance(p2, Point3)
p1 = self.project(p1)
p2 = self.project(p2)
item = self.canvas.create_line(p1.x, p1.y, p2.x, p2.y, **kargs)
self.items[item] = owner
return item
def draw_ellipse(self, owner, corners, **kargs):
assert all(isinstance(p, Point3) for p in corners)
item = self.draw_polygon(owner, corners, outline="#000000", smooth=1, **kargs)
self.items[item] = owner
return item
def draw_polygon(self, owner, pts, **kargs):
assert all(isinstance(p, Point3) for p in pts)
args = []
for p in pts:
p = self.project(p)
args.extend((p.x, p.y))
item = self.canvas.create_polygon(*args, **kargs)
self.items[item] = owner
return item
def draw_wireframe(self):
for drawable in self.drawables:
drawable.draw_wireframe(self)
def draw(self):
for drawable in self.drawables:
drawable.draw(self)
def update(self):
self.clear()
header = [
"(theta, phi): ({:.3f}, {:.3f})".format(self.theta, self.phi),
"(x, y, z): {}".format(self.camera_coords),
]
text = "\n".join(header) + "\n\n" + self.text
item = self.canvas.create_text((10, 10), anchor="nw", text=text)
self.items[item] = None
if self.wireframe:
self.draw_wireframe()
else:
self.draw()
def display(self):
self.update()
mainloop()
def _callback_commandline_up(self, event):
self.move_camera(0, math.pi / 16)
self.update()
def _callback_commandline_down(self, event):
self.move_camera(0, -math.pi / 16)
self.update()
def _callback_commandline_left(self, event):
self.move_camera(math.pi / 16, 0)
self.update()
def _callback_commandline_right(self, event):
self.move_camera(-math.pi / 16, 0)
self.update()
def _callback_commandline_equal(self, event):
self.scale *= 1.2
self.update()
def _callback_commandline_minus(self, event):
self.scale /= 1.2
self.update()
def _callback_commandline_shift_up(self, event):
self.y_offset -= 10
self.update()
def _callback_commandline_shift_down(self, event):
self.y_offset += 10
self.update()
def _callback_commandline_shift_left(self, event):
self.x_offset -= 10
self.update()
def _callback_commandline_shift_right(self, event):
self.x_offset += 10
self.update()
def _callback_commandline_shift_return(self, event):
self.reset_viewport()
self.update()
def _callback_button_1(self, event):
text = []
closest = self.canvas.find_closest(event.x, event.y)[0]
overlapping = self.canvas.find_overlapping(event.x, event.y, event.x+1, event.y+1)
if closest in overlapping and closest in self.items and self.items[closest] is not None:
text.append(self.items[closest].clicked(self, event, closest))
self.text = "\n".join(text)
self.update()
def _callback_button_1_motion(self, event):
pass