Displays the contents of a file from a Web server in a browser. : Browser : Tkinker PYTHON TUTORIALS


PYTHON TUTORIALS » Tkinker » Browser »

 

Displays the contents of a file from a Web server in a browser.


Displays the contents of a file from a Web server in a browser.
from Tkinter import *
import Pmw
import urllib
import urlparse

class WebBrowserFrame ):
   def __init__self ):
      Frame.__init__self )
      Pmw.initialise()
      self.packexpand = YES, fill = BOTH )
      self.master.geometry"400x300" )

      self.address = Entryself )
      self.address.packfill = X, padx = 2, pady = )
      self.address.bind"<Return>", self.getPage )

      self.contents = Pmw.ScrolledTextself,text_state = DISABLED )
      self.contents.packexpand = YES, fill = BOTH, padx = 5,pady = )

   def getPageself, event ):
      myURL = event.widget.get()
      components = urlparse.urlparsemyURL )
      self.contents.text_state = NORMAL

      if components== "":
         myURL = "http://" + myURL

      try:
         tempFile = urllib.urlopenmyURL )
         self.contents.settexttempFile.read() ) 
         tempFile.close()
      except IOError:
         self.contents.settext"Error finding file" )

      self.contents.text_state = DISABLED

WebBrowser().mainloop()



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Tkinker
» Browser