Problem per image on a Tkinter button

Asked

Viewed 1,673 times

0

I want to put image on buttons,I’ve done this way before,but agr n is working. Can you help me?

**Detail: **In the same window of Tkinter is instantiated the screen of a Turtle.

def images(self):
    imgAdd = tk.PhotoImage(file='./Images/add3.png').subsample(20,20)
    imgDel = tk.PhotoImage(file='./Images/menos.png').subsample(20,20)
    imgTrash = tk.PhotoImage(file='./Images/trash2.png').subsample(20,20)
    imgConfig = tk.PhotoImage(file='./Images/engre3.png').subsample(20,20)

    self.Widgets(imgAdd,imgDel,imgTrash,imgConfig)

def Widgets(self,*args):
    self.Add = tk.Button(self.frame_left,bd=0,image=args[0],command='')
    self.Add.grid(padx=10)
    self.Config = tk.Button(self.frame_left,bd=0,image=args[3],command='')
    self.Config.grid(padx=10)
    self.Trash = tk.Button(self.frame_left,bd=0,image=args[2]',command='')
    self.Trash.grid(padx=10)

1 answer

0

It was also with this problem but I solved standardizing the variable "image": self.botao.image= image.

So the code went like this

from tkinter import *

class Janela:
    def __init__(self, master):
        self.master = master
        self.master.geometry('300x200+200+100')

        self.botao = Button(self.master)
        imagem = PhotoImage(file='/Users/Luiz/Image/botao.png')
        self.botao.config(image=imagem)
        self.botao.imagem= imagem
        self.botao.pack()

root = Tk()
Janela(root)
root.mainloop()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.