You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a way to get the same behavior at execution between SPYDER and IDLE to get the following program run smoothly even if called several times. I tried so many ways, so many features. It's for demonstrating with several kind of machines. IDLE should lead the semantics of mainloop and friends, correct ? Don't answer to put a try: or something like this to avoid an error. Just show a portable Python version of this code, please... or will it depend finally on the IDE ? In my little head I suppose there exists such a beast. In the web, so many patches, so many solutions, many of them not working with Spyder. How the student user can know if he should go into a menu to modify the console behavior, or...
Thanks a lot, I'm on Mac mini m1 and Spyder 6.0.4
-w
#!/usr/bin/env python3# -*- coding: utf-8 -*-# spyder-collision-bug-at-end.py # sort of a code from an AI, working but terminating on errorimportturtleimporttimewindow=turtle.Screen()
window.title("Collision")
window.setup(width=600, height=200)
window.getcanvas().winfo_toplevel().focus_force()
window.tracer(False)
x , v=0, 4# position on a line, speedT=turtle.Turtle()
T. shape('circle')
defupdate_position():
globalx,vx+=vif (x<=-200) or (x>=200) : v=-vT.goto(x,0)
whileTrue:
window.update()
update_position()
time.sleep(0.01)
window.mainloop()
# _tkinter.TclError: invalid command name ".!canvas"
The text was updated successfully, but these errors were encountered:
Is there a way to get the same behavior at execution between SPYDER and IDLE to get the following program run smoothly even if called several times.
The only way your code can work in Spyder without any changes is by following these steps:
Go to the menu entry Run > Configuration per file
In Runner select External terminal
Click on Custom configuration to uncollapse those options.
Disable Interact with the interpreter after execution
After that you need to click in the menu entry Run > Run in external terminal. This will emulate the behavior you get when running in a terminal python spyder-collision-bug-at-end.py.
Since the interpreter window will be closed immediately after you close the Turtle window, users wouldn't see the error.
Don't answer to put a try: or something like this to avoid an error. Just show a portable Python version of this code, please...
I don't understand why not because
The error is present in IDLE too. This is what I see on Linux:
The error is (as far as I understand your code) expected because you're using an infinite While loop to update your animation and that will fail when the window is closed because there's no window canvas to update anymore.
That's what basically makes your script portable between IDEs. This is how I fixed it:
importtkinterimportturtleimporttimewindow=turtle.Screen()
window.title("Collision")
window.setup(width=600, height=200)
window.getcanvas().winfo_toplevel().focus_force()
window.tracer(False)
x , v=0, 4# position on a line, speedT=turtle.Turtle()
T. shape('circle')
defupdate_position():
globalx,vx+=vif (x<=-200) or (x>=200) : v=-vT.goto(x,0)
whileTrue:
try:
window.update()
exceptturtle.Terminator:
passtry:
update_position()
excepttkinter.TclError:
breaktime.sleep(0.01)
window.mainloop()
or will it depend finally on the IDE ?
It will, at least in Spyder's case. That's because by default we use the Jupyter architecture for execution in the IPython console. And that's not the same as a bare bones Python interpreter running your code behind the scenes (like in IDLE).
Is there a way to get the same behavior at execution between SPYDER and IDLE to get the following program run smoothly even if called several times. I tried so many ways, so many features. It's for demonstrating with several kind of machines. IDLE should lead the semantics of mainloop and friends, correct ? Don't answer to put a try: or something like this to avoid an error. Just show a portable Python version of this code, please... or will it depend finally on the IDE ? In my little head I suppose there exists such a beast. In the web, so many patches, so many solutions, many of them not working with Spyder. How the student user can know if he should go into a menu to modify the console behavior, or...
Thanks a lot, I'm on Mac mini m1 and Spyder 6.0.4
-w
The text was updated successfully, but these errors were encountered: