Skip to content
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

What is the correct way to include Azure theme with pyinstaller exe? #55

Closed
TheWicklowWolf opened this issue Feb 9, 2023 · 11 comments
Closed
Labels
help wanted Extra attention is needed

Comments

@TheWicklowWolf
Copy link

The Pyinstaller exe produces:
_tkinter.TclError: couldn't read file "azure.tcl": no such file or directory

@TheWicklowWolf TheWicklowWolf changed the title What is the correct way to make an exe with pyinstaller? What is the correct way to include Azure theme with pyinstaller exe? Feb 9, 2023
@sofronas
Copy link

sofronas commented Mar 2, 2023

You should add --collect-data sv_ttk in order to include.

@rdbende
Copy link
Owner

rdbende commented Mar 2, 2023

You should add --collect-data sv_ttk in order to include.

Clearly not, because this is Azure, not Sun-Valley.

However, I don't know how to make it work with Pyinstaller, I haven't really used it.

@rdbende rdbende added the help wanted Extra attention is needed label Mar 2, 2023
@sofronas
Copy link

sofronas commented Mar 2, 2023

Yeah, my fault! I thought you were using sv_ttk
If you want, you can use auto-py-to-exe. It's an GUI version of pyinstaller.

@TheWicklowWolf
Copy link
Author

TheWicklowWolf commented Mar 3, 2023

For pyinstaller one folder (-D):

--add-data "azure.tcl;" --add-data="theme\light.tcl;theme" --add-data="theme\dark.tcl;theme" --add-data="theme\light\*;
theme\light" --add-data="theme\dark\*;theme\dark"

For pyinstaller one file (-F):

--add-data "azure.tcl;" --add-data="theme\light.tcl;theme" --add-data="theme\dark.tcl;theme" --add-data="theme\light\*;
theme\light" --add-data="theme\dark\*;theme\dark"

and add this to into the python file:

    try:
      def get_path(filename):
        if hasattr(sys, "_MEIPASS"): #True if it's an exe
            return os.path.join(sys._MEIPASS, filename)
        else:
            return filename
      tcl_folder = get_path("azure.tcl")
      root.tk.call('source', tcl_folder)
      root.tk.call("set_theme", "light")
    except:
       pass

@rdbende rdbende pinned this issue Apr 17, 2023
@jhi2
Copy link

jhi2 commented Mar 27, 2024

To make it work with pyinstaller, you need a folder called Azure with the Azure ttk theme in it. Than, replace the theme code with this:

import darkdetect
def settheme(window):
    window.tk.call("source", "Azure/azure.tcl")
    window.tk.call("set_theme", "light")
    def change_theme():
    # NOTE: The theme's real name is azure-<mode>
        if window.tk.call("ttk::style", "theme", "use") == "Azure/azure-dark":
            # Set light theme
            window.tk.call("set_theme", "light")
        else:
            # Set dark theme
            window.tk.call("set_theme", "dark")
    is_dark = darkdetect.isDark()
    if is_dark:
        change_theme()
settheme(root)

And than, at least for autopytoexe select Additional Files > Add folder and than select Azure

@Imraanmohammed
Copy link

I have really tried many times but nothing seems to work. Please help me

@jhi2
Copy link

jhi2 commented Apr 29, 2024

put --add-data Azure at the end of the file. It also requires darkdetect because it runs the default Windows theme

@Imraanmohammed
Copy link

Imraanmohammed commented Apr 29, 2024 via email

@jhi2
Copy link

jhi2 commented May 5, 2024

Thank you. I don't really understand what you mean by darkdetect

On Mon, Apr 29, 2024, 1:11 AM jhi2 @.> wrote: put --add-data Azure at the end of the file. It also requires darkdetect because it runs the default Windows theme — Reply to this email directly, view it on GitHub <#55 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZ6JNLOYHSJL6RAUPC652ETY7WFZXAVCNFSM6AAAAAAUWP3KFSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBRG4YTANZXGI . You are receiving this because you commented.Message ID: @.>

It is a module. Here is the full command:
put darkdetect.py in the app dir and run
python -m pyinstaller somefile.py --add-data Azure --add-data darkdetect.py

@Imraanmohammed
Copy link

Imraanmohammed commented May 5, 2024 via email

@jhi2
Copy link

jhi2 commented May 5, 2024

Do you like the native theme support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants