Boa tarde Pessoal sou novo em python e utilizo o tkinter como GUI ,estou querendo salvar imagem que coloquei dentro do canvas em jpg, mas toda vez que salvo aparece um arquivo em branco
aki vai parte do codigo.
class telaQR:
def __init__(self,master):
self.labQr = Label( text="Texto do QRcode:", font="Arial, 12")
self.labQr.grid(row=0, column=0, padx=15, pady=15)
self.entrQr = Entry( width=70)
self.entrQr.grid(row=0, column=1, padx=5)
self.labQrNome = Label(text="Nome do QRcode:")
self.labQrNome.place(x=300,y=105)
self.entrQrNome = Entry(width=30)
self.entrQrNome.place(x=420,y=105)
self.botQrCriar = Button( text="Gerar QRcode", command=self.gerarQR, width=13, height=2, font="Verdana, 13")
self.botQrCriar.place(x=320, y=220)
self.botQrNome = Button( text="Salvar Como", command=self.salvarComo, width=13, height=2, font="Verdana, 13")
self.botQrNome.place(x=480, y=220)
self.panel = Canvas(width=240,height=240,background="black")
self.panel.place(x=40,y=70)
self.file_opt = options = {}
options['defaultextension'] = '.jpg'
options['filetypes'] = [('all files', '.*'), ('text files', '.jpg')]
options['initialdir'] = 'C:\Users\TI\Pictures'
options['initialfile'] = 'nome do arquivo.jpg'
options['parent'] = root
options['title'] = 'Salvar Como'
def gerarQR(self):
self.img = ImageTk.PhotoImage(file=r"C:\Users\TI\Pictures\Saved Pictures\palphas.jpeg")
self.panel.create_image(0, 0, image=self.img, anchor=NW)
self.panel.image = self.img
def salvarComo(self):
imgSave = self.panel.getint()
filename = tkFileDialog.asksaveasfilename(**self.file_opt)
if filename:
return open(filename, 'w')
filename.write(imgSave)
filename.close()
root = Tk()
telaQR(root)
root.geometry("620x380+150+50")
root.configure(background='Grey11')
root.title("Gerar QRcode")
root.mainloop()