1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How to implement a drag feature (or zoom) in a python window application?

Discussão em 'Python' iniciado por Stack, Novembro 23, 2025.

  1. Stack

    Stack Membro Participativo

    I'm doing some simple fractal drawings using turtle graphics in python and have encountered the situation where the turtle draws beyond the application frame. I want to be able to drag the view within the window so that I can center it over a different section of the fractal I am drawing or alternatively, Zoom in or out in order to manipulate the view.

    Does Python have a module for this? I am relatively new to python as I primarily program with Java and can think of many ways to do with Java and JFrames etc. My research for a simple python implementation has been fruitless :( and I don't want to be reinventing the wheel if there is a simple solution avaliable~ all methods are appreciated though. If I have missed another thread on this site that answers my question, please comment.

    here is my fractal code for anyone interested..

    import turtle

    t = turtle.Turtle()
    t.color("white")
    t.backward(450)
    t.color("red")

    def f2(length, depth):
    if depth == 0:
    t.forward(length)
    else:
    f2(length/2, depth -1)
    t.left(135)
    f2(length/8, depth -1)
    t.right(90)
    f2(length/8, depth -1)
    t.right(90)
    f2(length/8, depth -1)
    t.right(90)
    f2(length/8, depth -1)
    t.left(135)
    f2(length/2, depth -1)


    f2(400, 4)

    Continue reading...

Compartilhe esta Página