PyX 출력을 비트 맵으로 변환하여 Tkinter 응용 프로그램에 포함시켜야합니다. PyX 출력을 PIL 이미지로 직접 가져 오는 편리한 방법은 없지만 pipeGS 메서드를 사용하여 비트 맵을 준비하고 PIL을 사용하여로드 할 수 있습니다. 여기에 약간의 예가 있습니다.
import tempfile, os
from pyx import *
import Tkinter
import Image, ImageTk
# first we create some pyx graphics
c = canvas.canvas()
c.text(0, 0, "Hello, world!")
c.stroke(path.line(0, 0, 2, 0))
# now we use pipeGS (ghostscript) to create a bitmap graphics
fd, fname = tempfile.mkstemp()
f = os.fdopen(fd, "wb")
f.close()
c.pipeGS(fname, device="pngalpha", resolution=100)
# and load with PIL
i = Image.open(fname)
i.load()
# now we can already remove the temporary file
os.unlink(fname)
# finally we can use this image in Tkinter
root = Tkinter.Tk()
root.geometry('%dx%d' % (i.size[0],i.size[1]))
tkpi = ImageTk.PhotoImage(i)
label_image = Tkinter.Label(root, image=tkpi)
label_image.place(x=0,y=0,width=i.size[0],height=i.size[1])
root.mainloop()