Python乌龟:如何打开绘图
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()
包含图像数据的 PostScript 文件格式是 supported by the PIL
库。所以你可以像这样打开你的 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()
我有一个在 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()
包含图像数据的 PostScript 文件格式是 supported by the PIL
库。所以你可以像这样打开你的 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()