-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enhancement] Merging of PySimpleGUI EXE icons on the taskbar. EXEs were generated with pyinstaller. #6655
Comments
It's so great to hear from users like yourself that are enjoying using PySimpleGUI! It's hearing that PySimpleGUI is having a positive impact that keeps me motivated. There's a lot of information in this comment, but I don't have a conclusion I can give you. But maybe by trying some of these ways of looking at the files running you'll be able to piece together what may be happening on your system.... Since seeing your initial post on StackOverflow and asking you come open an issue, I've noticed a different behavior on my taskbar, even though the EXE file I'm running hasn't changed. Very odd that it sent from showing the Python.exe is the program running to now showing my EXE file is. I wanted to show you how to get information about the EXE file that's running by showing you some screenshots. If you right click the tastkbar, then you see the menu we've all seen.... I don't think it's commonly shown that you can then right click the EXE file shown in that menu to see another right click menu This one you can click Properties to get detailed information Combining icons problem... Application IDI'm wondering the code that sets the Application ID somehow plays a role in this. You'll find it near the end of the PySimpleGUI file. # Enables the correct application icon to be shown on the Windows taskbar
if running_windows():
try:
myappid = 'mycompany.myproduct.subproduct.version' # arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
except Exception as e:
print('Error using the taskbar icon patch', e) Or if it's entirely an effect that PyInstaller is causing. Two places to set the Icon and the TitleOne thing to be aware of is that there are TWO places icons can be specified in our tests. One is on the EXE file itself that PyInstaller creates for us. The other is when the PySimpleGUI Window is created. It's possible to have them differ, which will be quite confusing. The Window's title is also specified when the Window is created so there's again a chance for confusion. Here's a confusing test that I just ran..... I created EXE files using PyInstaller. One I made back in Sept 2023, the other I made last week... Note that the file named simple_popup.exe did not have an icon set when PyInstaller made the EXE. The other program does did. When I run the 2 exe files, I see this on my taskbar: When I right click these icons on the taskbar, I see that they claim to be the SAME EXE file.... Right clicking and choosing Properties provides the exact same information for both programs There's clearly some underlying problem that PyInstaller is creating (or maybe it's PySimpleGUI creating it)... regardless it's a side effect of PyInstaller + PySimpleGUI. |
Thank you very much for the detailed reply. On your first point I have been right-clicking on the taskbar icon and then right-clicking on the exe filename at the top, and then choosing Properties, as you suggested. But as the issue is that two or three applications are all sharing the same idon, I have only one icon to right-click. The Properties window that comes up refers to the first of the two or three apps that are sharing the icon. I have just repeated the exercise on a Windows 11 machine, recompiling with pyinstaller, and the same thing happens. I looked at the piece of code that you suggested, and noticed that it is present in the versions which fail, and not present in 4.57.0 which behaves correctly - and when I removed it from version 4.58.0 the problem went away!!! So - great result - thank you!! |
Thanks for the update! I didn't think about the fact that you're combining the icons..... and thus as you pointed out don't have multiple to choose from. I'll sneak something into the upcoming release to (hopefully) address this. I appreciate you opening an issue so we could work through it. |
Until the enhancement is released, you can control the App ID by making the same call that PySimpleGUI makes. You can do it by adding 1 line of code: sg.ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('mycompany.myproduct.subproduct.version') If you want icons to combine, then set the value to be the same in each application. If you don't want them to combine, then change it to a unique value in your code. It can be changed before creating each window if you want to control how each window combines with other windows in the same application. |
Thanks Mike. That did fix it, and I got two separate icons when running 4.60.5. But interestingly it didn't fix an accompanying feature of the bug - the loss of taskbar icon unless pinned. I didn't mention the second feature originally because I thought it would obscure the main merging icons issue. But I found that if I had the merging icons issues, it was also the case that the only way I could get the icons to display correctly on the taskbar (after double clicking their desktop shortcut icon) was by pinning them, and if I unpinned them they would revert back to the generic Python icon. This does not happen with 4.57.0: if you double-click a desktop shortcut icon, it appears correctly, and does not need to be pinned for you to see the correct icon. Removing the lines of code from 4.60.5 not only fixed the merging icons, it also fixed this secondary issue. But the one-line fix does not. |
Thanks for the added information. Are 100% of the executions you're talking about of EXE files created by PyInstaller? You're never running Python files, only EXE files made by PyInstaller? You may want to try using the psgshortcut application to see if it helps with your desktop shortcut problem. The reason for psgshortcut was to provide better control over icons. How are you creating your shortcuts? When running, on the taskbar, the icon should be controlled by the PySimpleGUI program itself. Whatever you use when creating your window is what should be shown. However, if icons are merged, then that's going to potentially mix things up. It sounds like there are situations as well where the Python icon is shown. I'm not sure of the different combinations that may be possible when launching from shortcuts. You can shortcut the .py file, the Python.exe file, a PyInstaller EXE, etc. It would be helpful to get the specific details and screenshots like I provided above. One reason you may not be seeing problems on earlier versions of PySimpleGUI is that the version may not have the ctypes call above. Given your different scenarios it's looking like a more extensive enhancement involving system settings to provide the ability to control whether or not the App ID is set. |
Give psgshortcut a try to see if it generates any different results.
The icon shown is not the Python icon.... that's the PySimpleGUI icon. The Python icon is rotated 90 degrees from the PySimpleGUI icon. Anytime you see this icon, it means you've not set an icon on your Window and PySimpleGUI is using the built-in default icon. It sounds like you're always setting it, but if you are setting the icon to your own, and ever see the PySimpleGUI icon, then you know something's up with your window creation. For icons on PySimpleGUI programs, I always bas64 encode them and include them in the Python source code. You'll find examples in all of the PySimpleGUI applications posted in this account. For example in the psgshortcut application, it's in the application source python file, in the main function. Given that this problem is only happening with PyInstaller, it's worth spending a little time investigating the kinds of problems others have run into and how they got past them.
I do, but am very tied up with getting the PySimpleGUI 5 release out the door. Doing my best to provide support to keep you moving ahead. |
Cool. Thank you. From my perspective this is not urgent at all. I can either keep using v 4.57.0, which works great, or if I really need the 4.60.5 upgrade, I can just use a version with the offending lines remmed out. Interesting about the rotated icon, I will keep a close lookout for that. And I will check out bas64 encoding them to include in the source file. Anyway - thanks very much for all your help, and I will leave you to focus on the PySimpleGUI 5 release. |
I almost universally encode and place image files that I may need directly into the PySimpleGUI programs. This stops problems of:
If you're expecting to see an icon, but are seeing the PySimpleGUI one instead, then that's a sign you've got one of the above problems (or others). The application The cases where you're seeing the PySimpleGUI icon when you think you should be seeing something else is an area you can debug or fix and it may get some of the problems you're seeing solved. |
I will give psgresizer a try. Thanks for the heads-up. |
For the shortcuts you create, regardless of how you create them, take a look at the settings for them. Here's a shortcut I made by right clicking and dragging. Note the "Start In" field. This is a really important setting because this field is what determines your "working directory". If your EXE is being "unpacked" and saving your icon files in a folder that's different than the working folder, then your PySimpleGUI program may not find the icon file. In my example, I'm using an icon file and creating my window using: window = sg.Window('Window Title', layout, icon='icon.ico') It runs and shows the icon I expect. If I then delete the value of the Starting In field, then it still works fine, I assume because the folder the shortcut is in is the same as where the icon is. If I get the folder to C:, then the icon I see is the PySimpleGUI icon, NOT the icon I set when I created the window. Nothing else changed, only the value in the shortcut. |
If you make the ctypes call with a different value for each EXE file, it still merges them? Please be careful when talking about "the bug" as there are TWO. I was addressing your shortcut problem. Perhaps another issue should be opened with these two separated. |
This is why there should be 2 issues. The first one, separate icons, IS fixed by making the provided code be different values for the string for each of your applications: sg.ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('mycompany.myproduct.subproduct.version') After that is when you introduced this second problem, the shortcut problem with icons that were incorrect. Let's pull these apart completely. |
Ok - cool. Because both issues appeared together in 4.58.0, and neither were present in 4.57.0, and because both were fixed by removing the 4 or 5 lines of code that you identified I took the view that they were two sides of the same coin. |
But, they're not. We can revisit this when I've got the capacity to spend more time on it. You've found a solution that works for you using old code and that's fine for now, but will certainly be a problem in the future. I'll give it a pause until I've got more time to spend on it and you've tot time to spend pulling these apart into 2 issues instead of looking at them the same. Thanks for trying the tests and providing data. Sorry I've not been able to get enough time into this to explain it all sufficiently. |
If you spend some time with the data presented in this issue, I think you would be able to get educated on how shortcuts work and why you were seeing the results you were seeing. There should be all you need to get your code working with the current version of PySimpleGUI, without deleting anything. I've added an enhancement to enable applications to set the IDs so that they can choose set applications to be the same, or even have different windows within the same application behave as if they are either the same or different applications from an icon combination point of view. It's in the PySimpleGUI 5 release in test now. Hopefully available soon! |
Ok - cool - though it would be great if later versions could behave as 4.57.0 behaves without needing to change the way that icons or shortcuts are created by the user. |
They won't. The brief explanation is that you've got bugs in your code and potentially in how you're packaging your PyInstaller EXE files. There's a backward compatibility issue as well. I understand that you can simply delete the code, but I can't as there are a lot of people relying on that code to get the behavior they're after in their application. We can work on it together more after the PSG 5 release gets posted if you've not figured it all out. BTW, I'm not saying any of this is easy. It's complicated. There are a lot of libraries involved, operating system behavior, settings, calls, lots of moving parts. We'll get it right one way or another. |
Not sure I understand this. The Python code is trivial and does virtually nothing. The only other code is a line calling pyinstaller: |
The code isn't finding your icon file, which is why you sometimes see the PySimpleGUI icon. That's why I explained the working directory with shortcuts, base64 encoding your icons, etc. |
The issue occurrs even without using shortcuts: I get exactly the same results when double-clicking the EXE icon in File Explorer as I did when double-clicking a desktop shortcut. I get shared icons on the taskbar. The icon is the PySimpleGUI icon unless I pin it to the taskbar. In that case it is the icon of the first of the two merged EXEs. If I use PySimpleGUI 4.57.0 (or 4.60.5 with the lines removed) it behaves as expected, with no merged icons. |
This means the .ico file is not being found. Have you base64 encoded it? I don't know where exactly PyInstaller is decompressing the file to. It's evidently not the same location as the "working directory". If the file you pass is "my_icon.ico", then it needs to be in the working directory, whatever that is set to. There should be some instructions in the PyInstaller docs that discuss how to access the files you've included in the EXE. Try to get your Python code to retrieve the file size of your .ico file using os.path calls. Get PySimpleGUI entirely out of the picture. |
Looking again at the bit of code which you mentioned earlier, surely that is the culprit because you are setting every appid to the same fixed string - so no wonder they all share the same icon.
|
Will the default for the enhancement be that icons do not merge? I think that would be very useful. |
The default behavior will be as it is today. The code is backwards compatible. You will have control, through the PySimpleGUI SDK, of the app ID. In the rely to the comment above, you indicated that the call did fix the problem. This is when you brought up the pinning/shortcut/icon problem. Let's pause on this until the release is posted and see where things are. |
I would really like to get this issue closed so you can have the results you're looking for... so let me try one more time to summarize and then we can revisit after PSG 5 gets launched. I don't want to have your problem get delayed due to the semi-controlled-chaos that happens after big software releases. I don't know how quickly I'll get back to this and you're closer than you think to being done with this. Your problems will disappear if you'll:
Your icon file is not being packaged into your EXE so that your python code can access it. Base64 encoding will remove the need to include the file in your EXE file. Your Python program is not finding the .ico file and I suspect that's because PyInstaller isn't being told to put it into your EXE. This is why you see the default icon on your window when it runs. It needs to be explicitly included as a file if you want to access it at runtime, as a file. The App ID call we already know fixes the merging problem. You'll have the option of switching to the new call being provided in PySimpleGUI 5, or you can even leave your call setting the APP ID the way you code it now and it will work. Good luck... I'm sure we'll get there eventually. This is likely your shortest path. |
Type of Issue Bug
Operating System - Windows 10
PySimpleGUI Port (tkinter, Qt, Wx, Web) - tkinter
Versions
Python version 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)]
PySimpleGUI Version 4.60.5
GUI Version 8.6.12
pyinstaller Version 3.6.0
Your Experience In Months or Years (optional)
Years Python programming experience 5 years
Years Programming experience overall 40 years+
Have used another Python GUI Framework? (tkinter, Qt, etc) tkinter
Anything else you think would be helpful?
Troubleshooting
These items may solve your problem. Please check those you've done by changing - [ ] to - [X]
Detailed Description
Any PySimpleGUI EXEs generated using pyinstaller share the same icon on the taskbar when using PySimpleGUI 4.60.5 (the most recent release). But this issue does not occur with PySimpleGUI 4.57.0 (though it does also happen with the release following 4.57.0 ie 4.58.0). It also occurrs with the version '4.61.0.206 Unreleased' from GitHub.
The image shows two different EXEs with different names (which would normally have different and separate icons) sharing the same icon on the taskbar
Running a third PySimpleGUI 4.60.5 EXE, the same thing happens, and all three share the same icon.
This happens with even the simplest of programs:
Code To Duplicate
The pyinstaller command takes the form:
pyinstaller --onefile --noconsole main.py --icon icon.ico
and using earlier versions of pyinstaller does not change anything.
The way I run the EXEs is by double-clicking a shortcut icon on the Desktop.
Screenshot, Sketch, or Drawing
Watcha Makin?
I've used PySimpleGUI in 30 odd programs, and it has been a delight to use: so thank you very much indeed for all the effort you put into creating and maintaining it. Recently I have used PySimpleGUI to build a journey times analyser which accesses Google Maps every hour to analyse traffic on specific routes over the days and weeks. Also an app for exploring embeddings with the OpenAI API.
The text was updated successfully, but these errors were encountered: