I am looking at python and I want to allow the user to click on the centre of the screen and create a circle, this is what I have.

Any help will be very appricated.

import from graphics *

def blueCircle():
    win = GraphWin("Click Here")
    p = win.getMouse()
    circle1 = Circle(Point(p.getX, p.getY) ,50)
    circle1.setFill("Blue")

Dani AI

Generated

The original snippet from had a few small syntax/usage issues that prevented a circle from appearing; 's reply fixes those and is a good minimal solution for drawing a fixed-radius circle on a mouse click. For a more interactive UX—pick the center with a click and set the radius by dragging—a simple Canvas-based approach gives live feedback and avoids hardcoding the radius.

Here is a compact Tkinter example that sets center on press, updates the circle while dragging, and finalizes on release:

import tkinter as tk
import math

def on_press(event):
    global cx, cy, oval
    cx, cy = event.x, event.y
    oval = canvas.create_oval(cx, cy, cx, cy, outline='blue', width=2)

def on_drag(event):
    r = math.hypot(event.x - cx, event.y - cy)
    canvas.coords(oval, cx - r, cy - r, cx + r, cy + r)

root = tk.Tk()
canvas = tk.Canvas(root, width=500, height=500)
canvas.pack()
cx = cy = 0
oval = None
canvas.bind("<Button-1>", on_press)
canvas.bind("<B1-Motion>", on_drag)
root.mainloop()

Troubleshooting notes and tips:

  • Method calls need parentheses (e.g., getX()), and most lightweight graphics libraries require an explicit draw/update step or an event loop to show shapes.
  • Zelle's simple graphics module is convenient for teaching, but compatibility with modern Python should be checked; for production or richer interaction, Tkinter or Pygame are better supported.
  • For precise radii, compute distance with math.hypot (as shown) instead of manual approximate math.
  • For more control (keyboard shortcuts, multiple shapes, undo), use Canvas event bindings or switch to Pygame for real-time input and double buffering.

Tkinter reference: tkinter docs. Pygame reference: Pygame docs.

This might just help you ...

# using the Zelle graphics module (derived from Tkinter)
# 
# draw a blue circle at mouse click point

from graphics import *

def blueCircle():
    w = 450
    h = 450    
    win = GraphWin("Click in window", w, h)

    p = win.getMouse()
    x = p.getX()
    y = p.getY()
    print(p, x, y)  # test

    circle = Circle(Point(x, y) ,50)
    circle.setFill("Blue")
    circle.draw(win)

    # wait till next mouse click
    p = win.getMouse()
    win.close()

blueCircle()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.