[Tutor] I'm clearly not getting an important pygtk concept

John pythontutoraccount at gmail.com
Fri May 25 18:07:38 CEST 2007


I created the following script to test my understanding of creating 
simple pygtk GUIs.

#!/usr/bin/python2.5

import gtk, urllib


def pinger_shotgun():
  """This function stores an object that pings Peter's writerscafe.org 
pages."""
  open_page = urllib.urlopen(web)

def plink(widget, web):
  print "I just pinged", web
  pinger_shotgun()

web = "http://www.mywebsite.com/"
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.connect("destroy", gtk.main_quit)
ping_button = gtk.Button("ping me")
window.add(ping_button)
ping_button.connect("clicked", plink, web)
window.show_all()
gtk.main()

I am not sure what's wrong with the script as I've typed it above.  I 
expected this script to generate a button with the label "ping me". I 
expected that when I press this button that my webserver log would show 
that someone with the user-agent python-urllb just tried to access my site.

This is not happening unfortunately.  Sometimes pressing the button 
registers in my logs and sometimes it does not.  Pressing  the button 
twice in rapid succession may cause a hit to register if a single click 
did not.  Pressing the button 5 or 6 times will cause 4 or 5 hits.  What 
is it I am not understanding?


John


More information about the Tutor mailing list