开发者

How to make "gtk.gdk.pixbuf_new_from_file()" use a relative path?

In gtk.gdk.pixbuf_new_from_file(image), if "image" is not an absolute path, I get:

glib.GError: Failed to open file 'image.pn开发者_如何学编程g': No such file or directory

That's unless I'm in the directory where the image lives.

note1: I'm running Debian Squeeze, which uses Python 2.6 by default.

note2: The image and the script live in one directory.


This is not specific to pixbuf_new_from_file, relative paths are always resolved relative to the current directory, which initially is the directory the script is started from.

You can get the directory the script is actually in with os.path.dirname(__file__). Then you can either make it your script's current directory with os.chdir, or you can use os.path.join to combine it with image.png.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜