Pmw ScrolledText Widget

Andrew Wheatley awheat at imaging.robarts.ca
Thu Sep 4 21:34:04 CEST 2003


In the text component, I use the insert method to insert a line of
text.
Initially, I set the foreground colour of the text component to
yellow, that is,
all text is yellow.  What I'd like to do is have different strings
have different coloured text.  You can't change the foreground color
of the text component without changing all the strings to the same
colour.  Anyone know how to have
different strings have different colours?

Here's a code snippet:

# One time creation of the widget
def AddMessageBox (self,parent):

    self._messageBox = Pmw.ScrolledText(parent,
				        hull_width = 850,
				        hull_height = 100,
     				        usehullsize=1)
    self._messageBox.grid(row=0,column=0)

    # Background is black, text color is yellow
    self._messageBox.component('text').configure(background='black')
    self._messageBox.component('text').configure(foreground='yellow')

    # Create a filename
    self._logfile = "Vcalc_Session_Log_"
    timestring = time.strftime("%d_%b_%Y_%H_%M_%S",time.localtime())
    self._logfile = "%s%s" % (self._logfile,timestring)

    # First line in the message box is yellow
    self._messageBox.insert('end','1: Log file is %s\n' %
(self._logfile,))
    self._messageBoxLineCount = 2
		
# Whenever this method is called in appends a string into the text
widget
# of the ScrolledText widget.  The 3rd parameter 'color' is supposed
to
# set the color of the string without changing all the previous
strings
# but I don't know how to do it yet.
def LogMessage(self,string,color):

    output = '%d: %s' % (self._messageBoxLineCount,string,)
    self._messageBox.insert('end',output)

    self._messageBoxLineCount = self._messageBoxLineCount + 1


--------------------
Thanks,

Andrew Wheatley




More information about the Python-list mailing list