Python龟:如何打开绘图

2024-10-02 16:30:42 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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()

Tags: 项目fromimport绘图部件tkinter绘制root
1条回答
网友
1楼 · 发布于 2024-10-02 16:30:42

包含图像数据的PostScript文件格式由^{}supported。因此,您可以像这样打开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()

相关问题 更多 >