⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imagemap.py

📁 Python.Tkinter编程实例代码多多学习
💻 PY
字号:
class Region:
    def __init__(self, coords, ref):
        self.coords = coords
        self.ref    = ref

    def inside(self, x, y):
        isSide = 0
        if self.coords[0][0] <= x <= self.coords[1][0] and \
           self.coords[0][1] <= y <= self.coords[1][1]:
            isSide = 1

        return isSide

class ImageMap:
    def __init__(self):
        self.regions = []
        self.cache   = {}

    def addRegion(self, coords, ref):
        self.regions.append(Region(coords, ref))

    def getRegion(self, x, y):
        try:
            return self.cache[(x,y)]
        except KeyError:
            for region in self.regions:
                if region.inside(x, y) == 1:
                    self.cache[(x,y)] = region
                    return region.ref
            return None

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -