Select to view content in your preferred language

Python Toolbox vs Addin - How to reference an image/icon for the tkinter app?

08-18-2023 12:28 AM
Occasional Contributor III

We created a tkinter app using a python toolbox. In this tkinter app we are able to change the photo in the header of the app using this code:

app = Tk("SAMPLE")
file_name = r'Images\\icon.png'
current_dir = pathlib.Path(__file__).parent.resolve() 
img_path = os.path.join(current_dir, file_name)
photo = PhotoImage(file = img_path)
app.iconphoto(False, photo)

 However, we would like to use this as an Addin. We followed these instructions: This worked fine until we inserted the lines 2-6 in above code. With these lines, the Addin won't start at all. We referenced the python-toolbox like this:

string installPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string toolboxPath = Path.Combine(installPath, "Sample.pyt\\Tool");
Geoprocessing.ExecuteToolAsync(toolboxPath, null, null, null, null, GPExecuteToolFlags.GPThread);

Within the Config.daml file of the Addin, we use the exact same icon using this reference: 

        <button id="Button1" caption="Caption" className="Button1" loadOnClick="true" smallImage="pack://application:,,,/Caption;component/Images/icon.png" largeImage="pack://application:,,,/Caption;component/Images/icon2.png">
          <tooltip heading="Tooltip Heading">Caption<disabledText /></tooltip>

I already tried to use the reference of the second code snippet in the first one. But unsurprisingly, it failed. Can anyone explain how I need to reference a .png-file used in tkinter in a python-toolbox which is referenced in an addin?

0 Replies