简体   繁体   中英

Python turtle library without display?

I want to run python code, which uses turtle library on my server, capture image of the result and save it to a file.

When I am connected to SSH, everything works - the turtle window displays on my computer, turtle draws image and the result is stored. However when I close the connection, turtle library stops working. I get error:

File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1813, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display "localhost:10.0"

The reason, why it fails is clear. Is it possible to create some kind of virtual display, to make Tk happy?

I found small utility called xvfb, which can emulate display. Then you can simply call xvfb-run python script.py and everything works!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM