Exemplo n.º 1
0
def get_image_path():
    width, height = 300, 150
    win = GraphWin("Image Path", width, height)
    win.setBackground(color_rgb(0, 0, 0))

    path_entry = Entry(Point(width // 2, height // 2 - 50), 30)
    path_entry.draw(win)

    ok_button = Rectangle(Point(width - 50, height - 50),
                          Point(width - 5, height - 5))
    ok_button.setFill(color_rgb(255, 255, 255))
    ok_button.draw(win)
    ok_button_text = Text(ok_button.getCenter(), "OK")
    ok_button_text.setSize(15)
    ok_button_text.draw(win)

    while True:
        click = win.getMouse()
        clickx = click.getX()
        clicky = click.getY()

        if ok_button.getP1().getX() <= clickx <= ok_button.getP2().getX(
        ) and ok_button.getP1().getY() <= clicky <= ok_button.getP2().getY():
            win.close()
            return str(path_entry.getText())
Exemplo n.º 2
0
class Button:
    def __init__(self, x, y, w, h, text, toggle):
        self.rect = Rectangle(Point(x, y), Point(x + w, y + h))
        self.text = Text(self.rect.getCenter(), text)
        self.toggle = toggle
        self.pressed = False
        self.func = None
        self.locked = False

    def press(self, win):
        if not self.locked:
            if (self.toggle):
                self.pressed = not self.pressed
            self.func(self.pressed)
            self.draw(win)

    def draw(self, win):
        if (self.pressed or self.locked):
            self.rect.setFill(color_rgb(100, 100, 100))
        else:
            self.rect.setFill(color_rgb(170, 170, 170))
        self.rect.undraw()
        self.rect.draw(win)
        self.text.undraw()
        self.text.draw(win)

    def isInside(self, x, y):
        xmin = self.rect.getP1().getX()
        ymin = self.rect.getP1().getY()
        xmax = self.rect.getP2().getX()
        ymax = self.rect.getP2().getY()
        return (xmin <= x <= xmax) and (ymin <= y <= ymax)

    def setFunc(self, func):
        self.func = func

    def lock(self, win):
        self.locked = True
        self.draw(win)

    def unlock(self, win):
        self.locked = False
        self.draw(win)