【问题标题】:Python Turtle : How to open a drawingPython Turtle:如何打开绘图
【发布时间】:2016-11-20 00:15:10
【问题描述】:

我有一个在 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()

【问题讨论】:

  • 取决于你如何保存它(哪种形式?)
  • @Billal BEGUERADJ 作为 PostScript 文件 (*.ps)

标签: python graphics tkinter drawing turtle-graphics


【解决方案1】:

包含图像数据的 PostScript 文件格式是 supportedPIL 库提供的。所以你可以像这样打开你的乌龟.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()

【讨论】:

  • 谢谢。但是你能告诉我如何使用海龟命令编辑该图像
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-04-30
  • 2016-07-20
  • 1970-01-01
  • 2019-05-29
  • 1970-01-01
  • 1970-01-01
  • 2019-08-08
相关资源
最近更新 更多