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())
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)
rect = Rectangle(Point(size / 2 - 25, 0), Point(size / 2 + 25, 50)) rect.setFill("red") rect.draw(win) g = -9.0665 / 100 v = 0 c = 0 u = 0 while True: bottom = size - rect.getP2().getY() rect.move(0, -v) v = u + g * c print(v) bottom += v c += 1 if bottom <= 0: u = -v c = 0 sleep(0.01)