tkinter virus

def _create_circle(self, x, y, r, **kwargs):
    """Create a circle

    x the abscissa of centre
    y the ordinate of centre
    r the radius of circle
    **kwargs optional arguments
    return the drawing of a circle
    """
    return self.create_oval(x-r, y-r, x+r, y+r, **kwargs)
tk.Canvas.create_circle = _create_circle

def _coords_circle(self, target, x, y, r, **kwargs):
    """Define a circle

    target the circle object
    x the abscissa of centre
    y the ordinate of centre
    r the radius of circle
    **kwargs optional arguments
    return the circle drawing with updated coordinates
    """
    return self.coords(target, x-r, y-r, x+r, y+r, **kwargs)
tk.Canvas.coords_circle = _coords_circle

def create(balls, canvas):
    """Create a drawing item for each solver.Ball object

    balls the list of solver.Ball objects
    canvas the Tkinter.Canvas oject
    return a dictionary with solver.Ball objects as keys and their circle drawings as items
    """
    return {ball: canvas.create_circle(ball.position[0], ball.position[1], ball.radius, fill="white") for ball in balls}

def update(drawing, canvas, step, size):
    """Update the drawing items for a time step

    drawing the dictionary of drawing items
    canvas the Tkinter.Canvas oject
    step the time step
    size the medium size
    """
    balls = drawing.keys()
    solver.solve_step(balls, step, size)
    for ball in balls:
        canvas.coords_circle(drawing[ball], ball.position[0], ball.position[1], ball.radius)
    canvas.update()

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source