1

I'm making an interactive map for my class, using Zelle's graphics.py . I got the map , and the data all set, but I can't figure out how to get the graphics window to update and draw new objects (route markers) on the map, after recieving user input. I've tried using a for loop and doing the update() method, no luck. Once the window is up, I'm supposed to get user input and the map is supposed to reflect that, and I can't figure out that last little bit.


from graphics import *

win = GraphWin("map" , 500,500)
win.setBackground("black")

textbox =  Entry(Point(250,250),10)
textbox.draw(win)

text = textbox.getText()


if text == "hello":

    line = Line (Point(100,100), Point(200,100))
    line.draw(win)


win.getMouse()
win.close() 

So once the desired User input is recieved how do i get the changes to show up on screen?

  • Please provide a runnable [mre]. – martineau Mar 28 '22 at 08:02
  • I'm kinda new to this, excuse all the rough edges, but the comment above provides a similar problem, once the desired user input is recieved on screen how do i get it to update on the screen – Taimintor6398 Mar 28 '22 at 08:21
  • We don't want you whole program. Please put any code in your question. – martineau Mar 28 '22 at 08:21
  • 1
    The Zelle `graphics` module only supports *very* limited user input capabilities — basically you can pause and wait for the user to click the mouse or check if user has typed a character and get it (or wait for them to type one). This means you'll have to create whatever GUI widgets, such as buttons and menus, you need/want on your own based completely on just those low-level methods. – martineau Mar 29 '22 at 01:21

1 Answers1

0

Your primary issue is that text = textbox.getText() executes before you get a chance to type input. This SO answer discusses this issue of Zelle graphics lacking an event model. What it recommends is you ask your user to click the mouse after entring input to force the program to wait:

from graphics import *

win = GraphWin("map", 500, 500)

textbox = Entry(Point(250, 250), 10)
textbox.draw(win)

win.getMouse()
text = textbox.getText()

if text == "hello":
    line = Line(Point(100, 100), Point(200, 100))
    line.draw(win)

win.getMouse()
win.close()

You can do that in a loop to get all your locations and use a keyword like "done" to break out of the mouse wait loop.

Your secondary issue is you were drawing a black line on a black background so you'd never see it had it worked correctly.

cdlane
  • 40,441
  • 5
  • 32
  • 81