-4
from graphics import*

def main():

    win = GraphWin("My Window",500,500)
    win.setBackground(color_rgb(0,0,0)) 

#Point 
    pt = Point(250,250)
    pt.setOutline(color_rgb(255,255,0))
    pt.draw(win) 


    win.getMouse()
    win.close() 

main()

How can I make the lines, the circle, and erase the background color so the result looks like the illustration?

Radar image

Matt Klein
  • 7,856
  • 6
  • 45
  • 46
  • 2
    Welcome to stackoverflow. What exactly do you want to achieve? A complex picture like the one you shared? An animation? – Nico Müller May 28 '20 at 20:27
  • Hi thanks. Yes, I intend to do something similar to the image, the project is with animations but I wanted to learn to do just the drawing, I can't find sources to learn how to use python graphics. – Vinícius Henrique May 28 '20 at 22:22
  • you should find some information if you will search `graphics.py` instead of `graphics`. OR even better search `python graphics.py`. ie. doc [Graphics](http://anh.cs.luc.edu/handsonPythonTutorial/graphics.html) – furas May 28 '20 at 23:02
  • BTW: you could also open file `graphics.py` to see source code - and you will see what classes and functions you can use. [source code](http://www.science.smith.edu/dftwiki/index.php/Zelle%27s_Graphics.py_for_Python_3). – furas May 28 '20 at 23:06
  • BTW: `graphics.py` is built on top of `tkinter` and you may have to learn also `tkinter` to use some functions which are not described in `graphics` but they are available - like `tkinter.after(milliseconds, function_name)` to run some function periodically and make animation. – furas May 28 '20 at 23:15

1 Answers1

1

This module is known also as graphics.py or Zelle's graphics and you should use these names to search more information.

Home Page for graphics.py with documentation and examples

Hands-on Python Tutorial > Graphics


You could also check source code to see all classes and functions.


This module is built on top of tkinter so you may have to learn also tkinter for some functions which are not available directly in graphics.py but you still can use it.

For example tkinter has after(milliseconds, function_name) to execute function with delay or repeate the same function after delay - so you can use it to create animation.

BTW: in after() has to be function's name without () and without arguments - and later tkinter will use () to execute it. It is called callback.


Example which uses after() to move point. This way it animates element and you still can click window to close program.

from graphics import * # PEP8: `import *` is not preferred 
import random

# --- functions ---

def move():
    dx = random.randint(-10, 10)
    dy = random.randint(-10, 10)
    pt.move(dx, dy)
    # move again after 100ms (0.1s)
    win.after(100, move)

# --- main ---

win = GraphWin("My Window",500,500)
win.setBackground(color_rgb(0,0,0))

pt = Point(250, 250)
pt.setOutline(color_rgb(255,255,0))
pt.draw(win)

# move first time after 100ms (0.1s)
win.after(100, move)

#win.mainloop()
win.getMouse()

win.close()

EDIT: after digging in information I created version without after()

from graphics import * # PEP8: `import *` is not preferred 
import random
import time

# --- main ---

win = GraphWin("My Window",500,500)
win.setBackground(color_rgb(0,0,0))

pt = Point(250, 250)
pt.setOutline(color_rgb(255,255,0))
pt.draw(win)

while True:
    if win.checkMouse():
        break
    dx = random.randint(-10, 10)
    dy = random.randint(-10, 10)
    pt.move(dx, dy)
    time.sleep(0.1)

win.close()
furas
  • 134,197
  • 12
  • 106
  • 148
  • Thank you very much, this will help me a lot in the project in the future. For now I am trying to learn how to draw radar (circles, lines), in the future I will give animation. – Vinícius Henrique May 29 '20 at 00:08
  • BTW: on Stackoverflow questions for `graphics` use tag [zelle-graphics](https://stackoverflow.com/questions/tagged/zelle-graphics) – furas May 29 '20 at 00:13