I'm making a program with Tkinter, I decided to use image buttons for easier to interact but PhotoImage by somehow not worked. The code example of the script contain image button:
from tkinter import *
class test:
def __init__(self,master):
self.master = master
img = PhotoImage(r'E:\v1.1\import.png')
b1 = Button(self.master, image = img).pack()
The script that contain source code that will load the above script:
from test2 import *
maingui = Tk()
gui = test(maingui)
maingui.mainloop()
By somehow the image is not loaded, leaving very small button. Anyone know what have I wrong?
EDIT 1: I have tried this solution (mentioned by acw1668) and edit the code of the first script but its not worked
from tkinter import *
class test:
def __init__(self,master):
global img
self.master = master
img = PhotoImage('E:\\v1.1\\import.png')
imglabel = Label(image=img)
imglabel.image = img
imglabel.pack()
b1 = Button(self.master, image = img).pack()
The results is the same as you can see on the link [1]: https://i.stack.imgur.com/Mo1XH.png
EDIT 2: I have tried to add self. into img and imglabel but its not worked too.
from tkinter import *
class test:
def __init__(self,master):
# I cannot global self.img so I have to delete it
self.master = master
self.img = PhotoImage('E:\\v1.1\\import.png')
self.imglabel = Label(image=img)
self.imglabel.image = self.img
self.imglabel.pack()
self.b1 = Button(self.master, image = self.img).pack()