代码拉取完成,页面将自动刷新
from tkinter import * # Import tkinter
width = 240
height = 120
class MainGUI:
def __init__(self):
window = Tk() # Create a window
window.title("Inside the circle?") # Set a title
self.canvas = Canvas(window, bg = "white", width = width, height = height)
self.canvas.pack()
self.canvas.create_oval(100 - 50, 60 - 50, 100 + 50, 60 + 50, tags = "circle")
self.canvas.bind("<B1-Motion>", self.isInside)
window.mainloop() # Create an event loop
def isInside(self, event):
self.canvas.delete("text")
if isInsideCircle(100, 60, 50, event.x, event.y):
self.canvas.create_text(event.x, event.y - 5,
text = "Mouse pointer is in the circle", tags = "text")
else:
self.canvas.create_text(event.x, event.y - 5,
text = "Mouse pointer is not in the circle", tags = "text")
def isInsideCircle(xCenter, yCenter, radius, x, y):
return distance(xCenter, yCenter, x, y) <= radius
def distance(xCenter, yCenter, x, y):
return ((xCenter - x) * (xCenter - x) + (yCenter - y) * (yCenter - y)) ** 0.5;
MainGUI()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。