PDA

View Full Version : Basic program in python...



Fxy
May 18th, 2013, 12:09 AM
HI everyone

Basically I am trying to create a basic python program that will contain a few buttons that when clicked will take you to specified hardcoded urls. Heres the code that I have written...


#!/usr/bin/python
import gtk
import pygtk
import webbrowser


window = gtk.Window()
window.set_title("Portal")
button = gtk.LinkButton("http://example.iana.org/", label="Button001")
window.add(button)
window.show_all()


gtk.main()

My problem is that whenever my app loads, I click on the button but get the error shown below.


PythonLinks.py:14: GtkWarning: Unable to show 'http://example.iana.org/': Operation not supported gtk.main()


I have tried running my app on 3 different machines. One running debian, another running ubuntu and finally a macbook. All three systems seem to produce the same error for some reason ?? If anyone could help me with this that would be totally awesome. Thanks in advance.

oldfred
May 18th, 2013, 05:15 AM
I have my own application with a database to scroll thru a bunch of pages and changed from gtk to qt.

But I have these links and think I had a working browser as in first example with gtk.
http://ardoris.wordpress.com/2009/04/26/a-browser-in-14-lines-using-python-and-webkit
http://www.aclevername.com/articles/python-webgui/

r-senior
May 18th, 2013, 07:49 AM
Before progressing much further, you should reconsider the use of pygtk. You should be using GObject introspection to access GTK.

The last post on this thread explains it very well:

http://ubuntuforums.org/showthread.php?t=2092094

Fxy
May 18th, 2013, 08:22 AM
I have my own application with a database to scroll thru a bunch of pages and changed from gtk to qt.

But I have these links and think I had a working browser as in first example with gtk.
http://ardoris.wordpress.com/2009/04/26/a-browser-in-14-lines-using-python-and-webkit
http://www.aclevername.com/articles/python-webgui/

Thanks for your reply.

If I use "webbrowser.open("http://example.iana.org/")" it automatically loads my default web browser with the specified page so I know the web browser part is working ok.




Before progressing much further, you should reconsider the use of pygtk. You should be using GObject introspection to access GTK.

The last post on this thread explains it very well:

http://ubuntuforums.org/showthread.php?t=2092094

What would you consider replacing "pygtk" with ?? Would it be better to go and use "qt" or should I stick with "gtk ?? Thanks for mentioning "gobject" I have that imported at the top of my code now.

MG&TL
May 18th, 2013, 08:41 AM
I've quickly edited this to use GObject, and it works just fine. If you replace:



import gtk
import pygtk

with:


from gi.repository import Gtk

And then replace all gtk references with Gtk, it works. I can post source code if you like, but I thought you'd prefer to figure this one out yourself. :)

Fxy
May 18th, 2013, 08:57 AM
I've quickly edited this to use GObject, and it works just fine. If you replace:



import gtk
import pygtk

with:


from gi.repository import Gtk

And then replace all gtk references with Gtk, it works. I can post source code if you like, but I thought you'd prefer to figure this one out yourself. :)

Thank you for your quick reply.

I tried using your code "from gi.repository import Gtk" from what you mentioned above, but now I get an import error.

ImportError: No module named gi.repository

Fxy
May 18th, 2013, 10:01 AM
Got everything working. Thanks for all the help. Your commands didn't work at first but they seem to be working now for some reason...