0

Ok, I am writing a client for the "instant messaging" server I just wrote. The client is in all Python, and the GUI is made with Tkinter.

Anyways, my first question is this: is there a way to make a scrollbar widget automatically scroll to the bottom?

Second, in a Text widget, how would I be able to make everything...colored? Example: "<Username> Message."
Would there be a way to make "username" blue and "message" say....green?

Thanks in advance

3
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by SoulMazer
0

is there a way to make a scrollbar widget automatically scroll to the bottom?

Use scrollbar.config ()
scrollbar.config( command = listbox_widget.yview )
listbox_widget.see(listbox_widget.size())

I think it is something like this for a text widget
Text.see(Text.END)

in a Text widget, how would I be able to make everything...colored

Most all of Tkinter's widget's have a background and foreground option. See the docs.

0

# optionally scroll to the bottom of the listbox
lines = listbox.size()
listbox.yview_scroll(lines, 'units')

0

Use scrollbar.config ()
scrollbar.config( command = listbox_widget.yview )
listbox_widget.see(listbox_widget.size())
I think it is something like this for a text widget
Text.see(Text.END)

Well, here is my code:

self.scrollbar = Scrollbar(master)
self.scrollbar.pack(side=RIGHT, fill=Y)
        
self.msgbox = Text(master, bg="black", fg="#0099cc") #33CCCC
self.msgbox.focus_set()
self.msgbox.pack()
        
self.msgbox.config(yscrollcommand=self.scrollbar.set)
self.scrollbar.config(command=self.msgbox.yview, bg="black", activebackground="#313131")
        
self.msgbox.see(self.msgbox.END)

And I receive this error:

self.msgbox.see(self.msgbox.END)
AttributeError: Text instance has no attribute 'END'

Most all of Tkinter's widget's have a background and foreground option. See the docs.

Ok, well I must have been a little unclear. I would like to make it multi-colored. As you can see in my code above, I have already set the main foreground and background colors for my Text widget, except would it be possible to do something like such?:

chatstr = "#FFFFFFHello,#000000World#FF0000!!
client.msgbox.insert(END, chatstr + "\n")

So "Hello" would be white, "World" would be black, and the two exclamation points would be red. Is that possible to do within the same widget?

Thanks again.

0

Sorry for the second post, but I missed sneekula's post.
@sneek: Ok, if I try your code I get the following error:

Traceback (most recent call last):
File "/home/foo/Documents/pyscripts/ChatProgram/Versions/Client/chatclient.v0.3.py", line 125, in <module>
client.msgbox = myapp.setup(master, client)
File "/home/foo/Documents/pyscripts/ChatProgram/Versions/Client/chatclient.v0.3.py", line 36, in setup
self.msgbox.yview_scroll(lines, "units")
File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 3167, in yview_scroll
self.tk.call(self._w, 'yview', 'scroll', number, what)
_tkinter.TclError: expected integer but got "0 0"

EDIT: Ok, I figured out that I receive a "TclError" if the contents of the widget isn't long enough to scroll through so I put your code within a "try" statement. However, if the contents of the widget is long enough, it doesn't scroll.

Thanks again.

0

Ok, well I finally solved this by myself. For the multi-color part, check this thread. For the part about an auto-scrollbar, I just repeatedly called the following code:

Text.yview(END)

Thanks to everybody that helped.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.