繁体   English   中英

Python Turtle:如何打开图形

[英]Python Turtle : How to open a drawing

我有一个在Canvas小部件上绘制乌龟的项目。 我已经知道如何保存图形,但是如何打开它们。 这是我要说的一个例子:

from tkinter import *
root = Tk()
... #Just creating widgets

def openDrawing:

...#What goes in here ?

fileMenu.add_command(label = "Open Drawing",command=openDrawing,accelerator="Ctrl+O")

root.mainloop()

PIL支持包含图像数据的PostScript文件格式。 因此,您可以打开您的turtle .ps文件,如下所示:

import PIL

# Load the .ps file using PIL
ps_file = PIL.Image.open("turtle_file.ps")
ps_turtle = PIL.ImageTk.PhotoImage(ps_file)
...
...
# Let us suppose you want to display it on a label
label = Label(image=ps_turtle)
label.image = ps_turtle # keep a reference
label.pack()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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