How to use tk.call ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jerry.levan@gmail.com

    How to use tk.call ?

    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.bi nd("<Button-4>",self.comman d.yview_scroll(-5 ,'units'))
    self.command.bi nd("<Button-5>",self.comman d.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.ta ble._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

  • James Stroud

    #2
    Re: How to use tk.call ?

    jerry.levan@gma il.com wrote:[color=blue]
    >
    > I can't find how too use tk.call, can anyone give me a clue as to how
    > to
    > solve my problem?[/color]

    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
    <built-in method call of tkapp object at 0x403f54b8>
    [color=blue]
    > I have tried the following:
    >
    > self.table.bind ("<Button-4>",self.table. tk.call(self.ta ble._w,'yview', 'scroll',-5,'units')[/color]

    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


    Comment

    • jerry.levan@gmail.com

      #3
      Re: How to use tk.call ?

      >> self.table.bind ("<Button-4>",self.table. tk.call(self.ta ble._w,'yview', 'scroll',-5,'units')
      [color=blue]
      >I haven't used Table, but are you sure that what you are calling
      >"self.table " here actually has mouse focus?[/color]
      [color=blue]
      >James[/color]

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

      Jerry

      Comment

      • Eric Brunel

        #4
        Re: How to use tk.call ?

        On 29 May 2006 21:13:07 -0700, <jerry.levan@gm ail.com> wrote:
        [color=blue][color=green][color=darkred]
        >>> self.table.bind ("<Button-4>",self.table. tk.call(self.ta ble._w,'yview', 'scroll',-5,'units')[/color][/color]
        >[color=green]
        >> I haven't used Table, but are you sure that what you are calling
        >> "self.table " here actually has mouse focus?[/color]
        >[color=green]
        >> James[/color]
        >
        > Yup, I click on the table, and then frantically work the mouse wheel to
        > no
        > effect...[/color]

        .... which is quite normal, since you actually didn't define any binding.
        What you did is:
        - *Call* self.table.tk.c all(self.table. _w,'yview','scr oll',-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:


        HTH
        --
        python -c "print ''.join([chr(154 - ord(c)) for c in
        'U(17zX(%,5.zmz 5(17l8(%,5.Z*(9 3-965$l7+-'])"

        Comment

        • jerry.levan@gmail.com

          #5
          Re: How to use tk.call ?

          Eric,

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

          Jerry

          Comment

          • Eric Brunel

            #6
            Re: How to use tk.call ?

            On 30 May 2006 05:51:04 -0700, <jerry.levan@gm ail.com> wrote:
            [color=blue]
            > Eric,
            >
            > Thanks, your tip did the trick... Is there someplace where tk.call is
            > discussed?[/color]

            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...
            --
            python -c "print ''.join([chr(154 - ord(c)) for c in
            'U(17zX(%,5.zmz 5(17l8(%,5.Z*(9 3-965$l7+-'])"

            Comment

            Working...