How to display and change an icon inside a python Tk Frame
- by codingJoe
I have a python Tkinter Frame that displays several fields. I want to also add
an red/yellow/green icon that will display the status of an external device.
The icon is loaded from a file called ICON_LED_RED.ico.
How do I display the icon in my frame?
How do I change the icon at runtime?
for example replace BitmapImage('RED.ico') with BitmapImage('GREEN.ico')
class Application(Frame):
def init(self, master=None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
def createWidgets(self):
# ...other frame code.. works just fine.
self.OKBTN = Button(self)
self.OKBTN["text"] = "OK"
self.OKBTN["fg"] = "red"
self.OKBTN["command"] = self.ok_btn_func
self.OKBTN.pack({"side": "left"})
# when I add the following the frame window is not visible
# The process is locked up such that I have to do a kill -9
self.statusFrame = Frame(self, bd=2, relief=RIDGE)
Label(self.statusFrame, text='Status:').pack(side=LEFT, padx=5)
self.statIcon = BitmapImage('data/ICON_LED_RED.ico')
Label (self.statusFrame, image=self.statIcon ).grid()
self.statusFrame.pack(expand=1, fill=X, pady=10, padx=5)