How to use tk.call ?

J

jerry.levan

Hi,

I am trying to port one of my Tcl/Tk apps to Python ( 2.4.2/3).
One task is to try to be able to use my wheel mouse to scroll a Tktable
object.

The tcl code looks like:
#Support the MouseWheel

bind $ui_vars(table) <Button-4> { $ui_vars(table) yview scroll -5
units }
bind $ui_vars(table) <Button-5> { $ui_vars(table) yview scroll +5
units }
bind $ui_vars(code) <Button-4> { $ui_vars(code) yview scroll -5
units }
bind $ui_vars(code) <Button-5> { $ui_vars(code) yview scroll +5
units }

$ui_vars(table) is the table and $ui_vars(code) is a text widget.

on the python side I can get scrolling in the text widget by
# Support for mouse wheel
self.command.bind("<Button-4>",self.command.yview_scroll(-5 ,'units'))
self.command.bind("<Button-5>",self.command.yview_scroll(5,'units'))

Unfortunately the python Tkinter Table widget does not support the
yview_scroll command.

I have tried the following:

self.table.bind("<Button-4>",self.table.tk.call(self.table._w,'yview','scroll',-5,'units')
but, alas nothing happens....

I can't find how too use tk.call, can anyone give me a clue as to how
to
solve my problem?

Thanks,

Jerry
 
J

James Stroud

I can't find how too use tk.call, can anyone give me a clue as to how
to
solve my problem?

py> from Tkinter import *
py> tk = Tk()
py> tk.tk
<tkapp object at 0x403f54b8>
py> tk.tk.call
<built-in method call of tkapp object at 0x403f54b8>


Also, any widget should have a tk (which has a call):

py> b = Button(tk, text='button')
py> b.tk
<tkapp object at 0x403f54b8>
py> b.tk.call
I have tried the following:

self.table.bind("<Button-4>",self.table.tk.call(self.table._w,'yview','scroll',-5,'units')

I haven't used Table, but are you sure that what you are calling
"self.table" here actually has mouse focus?

James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
 
J

jerry.levan

self.table.bind( said:
I haven't used Table, but are you sure that what you are calling
"self.table" here actually has mouse focus?

Yup, I click on the table, and then frantically work the mouse wheel to
no
effect...

Jerry
 
E

Eric Brunel

Yup, I click on the table, and then frantically work the mouse wheel to
no
effect...

.... which is quite normal, since you actually didn't define any binding.
What you did is:
- *Call* self.table.tk.call(self.table._w,'yview','scroll',-5,'units'),
which did the scroll;
- Pass the *result* of this call (which is probably None or the empty
string) as the second parameter of self.table.bind.
So no binding was defined.

One solution is to define the binding via a lambda, like this (untested):
self.table.bind("<Button-4>", lambda e, t=self.table: t.tk.call(t._w,
'yview', 'scroll', -5, 'units'))

For more information on lambda, see here:
http://docs.python.org/tut/node6.html#SECTION006750000000000000000

HTH
 
J

jerry.levan

Eric,

Thanks, your tip did the trick... Is there someplace where tk.call is
discussed?

Jerry
 
E

Eric Brunel

Eric,

Thanks, your tip did the trick... Is there someplace where tk.call is
discussed?

I don't think so. I personnally never find any documentation on it. But
there is not much to say: you can just pass regular tcl commands through
it and that's all. The only thing to remember is to split your command in
"words" as tcl expects them. But you seem to have figured out that
already...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,296
Messages
2,571,535
Members
48,281
Latest member
DaneLxa72

Latest Threads

Top