0

So I'm a bit confused here... I managed to change the icon for the main window of my program, but when I try to create a second window and change the icon of that away from the base tkinter icon it spits back an error. I really don't understand this code, just googled how to do it and this is what it spit back so just copied and pasted it into my program.

from tkinter import *
import os
from PIL import *

class Main():
    def __init__(self,root):
        root.title("Program Title")
        path = getDir() + "/Resources/appIcon.gif"
        img = Image("photo", file=path)
        root.tk.call('wm','iconphoto',root._w,img)
        #^^ This is the one that's working properly.

    def secondWindow(self):
        self.root2 = Tk()
        self.root2.title("New Window")
        path = getDir() + "/Resources/appIcon.gif"
        img = Image("photo",file=path)
        self.root2.tk.call('wm','iconphoto',self.root2._w,img)
        #^^ This is the one... That's not working


def getDir():
    path = __file__.strip("/programName.py")
    return path

root = Tk()
Main(root)
root.mainloop()

So the main window (root) shows the appIcon.gif located in the path I specified. When I load the secondWindow function tho, it spits me back this:

self.root2.tk.call('wm','iconphoto',self.root2._w,img)
_tkinter.TclError: can't use "pyimage11" as iconphoto: not a photo image

So uh... What stupid mistake am I making? Literally just copy and pasted the code then changed root to self.root2 (Originally I tried it as root, thought there might be a conflict even tho root wasn't being passed so changed it to self.root, still no luck so changed it to self.root2, still no luck...)

0 Answers0