1. I have in a frame a listbox to wich i add items during the running of a
programm.
How can i force the listbox to allways show the latest items, this should be a
forced scroll function?
Here's the definition of my listbox:
# --- Create history lisbox ---
self.scroll=Scrollbar(self)
self.list = Listbox(self)
self.list.config(yscrollcommand=self.scroll.set, relief=SUNKEN)
self.list.pack(side=LEFT, expand=YES, fill=BOTH)
self.scroll.config(command=self.list.yview, relief=SUNKEN)
self.scroll.pack(side=RIGHT, fill=BOTH)
2. I need a function that does the equivalent of the 'on timer (xx)'function in
many programming languages.
The function should do something every xx msec without blocking the rest of the
programm. Is this possible with python?
Thanks in advance
Rony STEELANDT
e-mail : RStee...@aol.com
Greetings from france :)
I do not know of a way to set up a listbox to always display the
end of its list. I accomplish what you describe by calling the
yview method of the listbox every time I add an element to it.
If you have not discovered the tkman "demo", it is a browser for the
Tk man pages. (You can just use the man pages directly, but then you
have to figure out the name of what you're looking for in advance--
for example, the listbox man page is called TK_listbox.)
I usually use the things described in the man pages, along with the
Tkinter life preserver, to figure out how to do the Tk stuff in python.
I did a lot of Tkinter programming with the "old" life preserver, which
did not mention all the methods and their arguments that were actually
implemented, so sometimes you have to poke around in the Tkinter dictionary
and experiment to see what functions are really there.
Frederick Lundh has improved the Life Preserver, however, so some of
these problems with it are probably fixed. I believe you can get to
this document from the Python home page. If you don't find a reference
to it directly, follow the link to the starship, go to the crew quarters,
look for Frederick Lundh, and hunt around in his page there.
(By now, he has no doubt responded to your message with better details
than I have here. :-)
(I think something like self.list.yview('moveto', 1.0) will cause your
listbox to display the end of its list.)
sue
Use the 'see' method:
list.insert(END, "item")
list.see(END) # make sure it's visible
>2. I need a function that does the equivalent of the 'on timer (xx)'function in
>many programming languages.
>The function should do something every xx msec without blocking the rest of the
>programm. Is this possible with python?
Tkinter offers the 'after' method:
w.after(ms, callback)
which calls the given callback (typically a bound method or a function)
after ms milliseconds. 'after' installs a one-shot timer, so you have to call
it again from within the callback. I usually do something like:
def __init__(self, master, ...):
...
self.poll() # get things going
def poll(self):
...
self.master.after(500, poll) # poll every 500 ms
Cheers /F
fre...@pythonware.com
http://www.pythonware.com