On Feb 17, 1:25 pm, "Joshua J. Kugler" <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Hi, > > > I'm going around in circles so I'm asking for help. I want to read a > > simple text file and output the contents to a GUI window when I click > > on a button. I have written a small python program to read the > > contents of a file when a button is clicked but can only output this > > to a console window. I'm using the pygtk binding with glade for the > > gui. > > > I know it must be quiet simple but a mental block has rapidly > > descended. > > > Any help would be appreciated. > > What does your code look like? What are you using to print? Are you > writing to the GUI or using the 'print statement?' > > j > > -- > Joshua Kugler > Lead System Admin -- Senior Programmerhttp://www.eeinternet.com > PGP Key:http://pgp.mit.edu/ ID 0xDB26D7CE > > -- > Posted via a free Usenet account fromhttp://www.teranews.com
This is the code, it was adapted from code I found on the net. Code as follows, #!/usr/bin/python import pygtk import gtk import gtk.glade import string import os import gobject class gui: def __init__(self): self.wTree=gtk.glade.XML('dansgui.glade') dic = { "on_Read_File": self.on_Read_File, "on_cancel": (gtk.main_quit)} self.wTree.signal_autoconnect(dic) self.count = 0 self.win = self.wTree.get_widget("window1") self.win.connect("delete_event", self.on_delete_event) self.win.show() def on_Read_File(self, widget): print "Opening Dansguardian bannedsitelist file for reading..." print; print lineoftext = open('/etc/dansguardian/lists/bannedsitelist', 'r') myarray = [] lnum = 0 for line in lineoftext: line = line.rstrip('\n') line = line.rstrip( ) lnum = lnum + 1 print lnum , line myarray.append(line); lineoftext.close( ) def on_delete_event(self, widget, event): self.win.set_sensitive(False) dialog = gtk.MessageDialog(self.win, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO, gtk.BUTTONS_YES_NO, None) dialog.set_markup('<big><b>Are you sure you want to quit?</ b></big>') dialog.connect("destroy", lambda w: self.win.set_sensitive(True)) answer = dialog.run() if answer == -8: dialog.destroy() return False if answer == -9: dialog.destroy() return True app = gui() gtk.main() -- http://mail.python.org/mailman/listinfo/python-list