Reputation: 1
I am relatively new to python turtle and am experimenting around. I am trying to draw a displacement-angle graph for certain motions depending on the equation the user provides. I plan to store everything into one data file so that I can keep adding new data without changing the file directory where python reads. I've decided to compile each set of data into a list item and run the whole program through a for loop to read the data set by set. For eg, reading set1's data, plotting the graph and prompting for a user input to reset the turtle screen and read in set2's data...
However, I am stuck on the last part where after the graph has been plotted for the first data set, the user needs to prompt(left click on the turtle screen) to exit the screen/clear the screen and draw the new data set. Ive tried turtle.clearscreen() and turtle.exitonclick() but it always gives me a turtle.Terminator error`
canvas = turtle.Screen()
for item in fulldatalist:
**filter and check valid data #assume valid data in this case)
turtle.setworldcoordinates(llx,lly,urx,ury) #the 4 values are based on the data input
**code for drawing of graph
canvas.exitonclick()
this is the code i am currently using(**is the pseudocode for the other parts) but it gives me an error: _tkinter.TclError: invalid command name ".!canvas".
I only receive all the errors mentioned after the first graph has been drawn, and the user clicks on the screen. The code portion for drawing of graph works when i just use 1 data set.
Appreciate any help :) Tysm!
EDIT: I changed it a little so it looks like this now
for item in fulldatalist:
canvas = turtle.Screen()
**filter and check valid data #assume valid data in this case)
turtle.setworldcoordinates(llx,lly,urx,ury) #the 4 values are based on the data input
**code for drawing of graph
done = input('enter to proceed with next data set')
canvas.resetscreen()
this works well however i realised its quite inconvenient as the user has to tab back to the terminal and press enter to move to the next dataset. Is it possible to use exitonclick or any functions which allows closing the window/clicking the window to move to the next data set?
Upvotes: 0
Views: 208
Reputation: 41905
You seem to have two misconceptions about canvas.exitonclick()
. First, it doesn't stop and wait for a click to happen, it simply registers some code to run if/when a click happens. Second, the exit
in it's name means "tear down the turtle system and exit from mainloop()
". Not what you want.
I could picture doing it this way:
def present_data():
screen.onclick(None) # disable handler inside handler
item = fulldatalist.pop()
screen.resetscreen()
# filter and check valid data #assume valid data in this case)
screen.setworldcoordinates(llx, lly, urx, ury)
# code for drawing of graph
if fulldatalist:
screen.onclick(present_data) # reenable handler
screen = turtle.Screen()
present_data()
But not working with complete code, I can't test this.
Upvotes: 0