Convert canvas to image in python 3.3

后端 未结 1 1534
一生所求
一生所求 2021-01-16 13:16

I want to make canvas and user will draw some picture in that which I want to save as Image. I am using Python 3.3.2. It doesn\'t support PIL or Image module. Can someone gu

相关标签:
1条回答
  • 2021-01-16 13:45

    Maybe it's a bit too late to answer this question. But, I'll still go ahead.

    from tkinter import *
    import pyscreenshot as ImageGrab
    
    r=Tk()
    canvas = Canvas(r,height=1000,width=2000,bg="snow") 
    def getter():
        x2=r.winfo_rootx()+canvas.winfo_x()
        y2=r.winfo_rooty()+canvas.winfo_y()
        x1=x2+canvas.winfo_width()
        y1=y2+canvas.winfo_height()
        print("save")
        ImageGrab.grab().crop((x2,y2,x1,y1)).save("./test.jpg")
    
    
    b1=Button(r,text="Save",command=lambda:getter())
    b1.grid()
    

    Let me know if this doesn't work. Hope it helps..

    0 讨论(0)
提交回复
热议问题