473,804 Members | 2,194 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pmw ScrolledText Widget

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._messageBo x = Pmw.ScrolledTex t(parent,
hull_width = 850,
hull_height = 100,
usehullsize=1)
self._messageBo x.grid(row=0,co lumn=0)

# Background is black, text color is yellow
self._messageBo x.component('te xt').configure( background='bla ck')
self._messageBo x.component('te xt').configure( foreground='yel low')

# Create a filename
self._logfile = "Vcalc_Session_ Log_"
timestring = time.strftime(" %d_%b_%Y_%H_%M_ %S",time.localt ime())
self._logfile = "%s%s" % (self._logfile, timestring)

# First line in the message box is yellow
self._messageBo x.insert('end', '1: Log file is %s\n' %
(self._logfile, ))
self._messageBo xLineCount = 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._messageB oxLineCount,str ing,)
self._messageBo x.insert('end', output)

self._messageBo xLineCount = self._messageBo xLineCount + 1
--------------------
Thanks,

Andrew Wheatley
Jul 18 '05 #1
1 3057

"Andrew Wheatley" <aw****@imaging .robarts.ca> schrieb im Newsbeitrag
news:d4******** *************** ***@posting.goo gle.com...
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?


Text is a very versatile widget! Read the spec! You will have to use tags.

from Tkinter import *

t=Text()
t.pack()
t.tag_config('n ice',background ='green')
t.tag_config('r everse',backgro und='black',for eground='white' )

t.insert('end', "NICE","nice"," REVERSE","rever se")
mainloop()
Kindly
Michael P
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3747
by: Srinath Avadhanula | last post by:
Hello, Sorry to be bringing up what seems to be a somewhat beaten up topic... This is what I wanted to do: Create a _simple_ text editor widget which supports VI(M) style keybindings but works with arbitrary fonts/unicode characters. Vi(m) unfortunately, does not support Devanagari (or proportional fonts) and it looks like it will take quite some time for these things to work. As
0
1149
by: Donald L. Dietmeyer | last post by:
I am attempting to put together a "dumb terminal" using a Pmw.ScrolledText to communicate via a serial port with a box that does the echoing of characters it receives. How can I stop the ScrolledText from echoing characters typed to it? Or lacking that, how can I know when a character has been echoed so that I can write a backspace to the displayed text? Maybe there is a better widget for this application?
2
2957
by: Tonino | last post by:
Hi, I have a small Tkinter app that gets data from a socket connection to a "server". The app has a Text() widget to display the info that it gets from the socket connection. I have the ability to stop the text at any point. What I want to be able todo is select a line from the Text() window and double click or whatever on it to open a new window with that selected text as a paramater to the new window.
6
10327
by: William Gill | last post by:
I am trying to get & set the properties of a widget's parent widget. What I have works, but seems like a long way around the block. First I get the widget name using w.winfo_parent(), then i convert the name to a reference using nametowidget(). self.nametowidget(event.widget.winfo_parent()).hasChanged= True It works, but I can't help but think I'm missing a more direct route. Am I? Bill
5
4112
by: nik | last post by:
I've been trying to get the scrollbar and text box always going to the last line and have been completely unsuccessful. I've tried, ScrolledText, text.see, and text.yview_pickplace without success for instance this was the last setup: self.text = ScrolledText(master, relief=RIDGE) self.text.grid(column=1, row=2, columnspan=10,\
3
1665
by: mariox19 | last post by:
Are Tkinter widgets running on their own thread? If I try to make a simple application that will print the letters A to Z to a Tkinter Text widget, and I space the printing of each letter by 1 second, it seems no text will appear in the Text widget until the method exits. Take a look at this snippet: # Assume I have created no threads other than the one that comes
3
1459
by: xqxq | last post by:
I have a problem with a ScrolledText. I'm defining a function, which I would like to make a new window with only ScrolledText on it. I'm adding text from file 'zasady.txt', but it is not visible until i highlight the text using a mouse. What am I doing wrong? def zas(): pl=END ro=Tk() f=Frame(ro) f.pack(expand=1, fill=BOTH) st=Text(f, background="white") st.pack(fill=BOTH, expand=1)
0
995
by: Phil Thompson | last post by:
On Sunday 04 May 2008, Lance Gamet wrote: I think QMainWindow.setCentralWidget() is what you are looking for. The eric4 IDE probably covers most things you'll ever need. Phil
0
947
by: lekin2 | last post by:
So what the heck is going on. I have a Pmw.ScrollingCanvas and inside I put a Pmw.ScrollingText and that all works but I can't get it to scroll. I was thinking I needed an event like: self.sc = Pmw.ScrolledCanvas(parent, borderframe = 5, labelpos = 'n', usehullsize = 1, hull_width = 700, hull_height = 500,
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10603
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3836
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.