Open .glade file in another directory

Hi, I’m using the following lines to load a .glade file located in the home directory. builder = Gtk.Builder() builder.add_from_file("") Since the python file is located in .local/bin and it is accessible from all directory, there is a way to tell the add_from_file function to open that file from the home directory and not from the current directory? Thanks in advice.



Of course really you want to use gresouce + datadirs rather than keeping stuff in $HOME

I tried that but it won’t work: builder.add_from_file("~/") I get no such file or directory. I think I’m missing something.
I kept that in the home only for solving this problem easier (i don’t want to mess with complex path rn)

~ is only interpreted by your shell. You should use the absolute/relative path instead.


In that case it might be an issue, since it is a GUI project not only for me. Project
I think i found a solution: I can get the home directory previously and set the argument of add.from_file()as a variable

It’s not an issue really. You should package those files with your .pyfiles and handle the path yourself.

Ok, thanks for the help

Yes this is what you need to do “mostly”. Convert the relative path to absolute path. But as others said, consider putting the Glade file into GResource. :smiley:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.