Hi guys.

I'm trying to access some User interface files (.glade) which are in a subdirectory.

from gi.repository import Gtk
import os

path=os.getcwd+'/ui/main.glade'
def hurr():
    builder=Gtk.Builder()
        builder.add_from_file(path) # get UI file
    window=builder.get_object('winlet')
    window.show()
hurr()
Gtk.main()

This works if i use only 1 glade file, but i have multiple .glade files that i will need to use.
Is there away to include the UI directory(ui) into the python path, so that i'll not have to add the path for each glade file?

Recommended Answers

All 4 Replies

Hi Zeref

I have not worked with Gtk before (Only Tkinter) but maybe I can help.

You could set the current working directory (cwd) to the path you require (excluding the file name) using

os.chdir(path)

You could then also pass the filename into the function:

def hurr(filename):
    builder=Gtk.Builder()
    builder.add_from_file(filename) # looked for in the cwd changed using os.chdir
    window=builder.get_object('winlet')
    window.show()

hurr('newfile.glade')
Gtk.man()

I didnt undestand your question. Do u mean u need 2 traverse through the ui folder too? and btw, just out of curiosity, is the path correct ? ?

soliver: I tried your solution, It works. thanks a lot.

i decided to use:

path=os.path.join(os.getcwd(),'ui')
os.chdir(path)
def .....

extr3mex, yes I need to traverse to the ui folder and the path is correct.

Glad it was of help Zeref.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.