Accessing tcl/tk global variables from callbacks

Discussion in 'Ruby' started by Bojan Petrovic, Dec 2, 2005.

  1. Is there a way to access tcl global variables from a callback by directly
    using tcl code?
    This code does not work:

    ##test.rb###############
    require 'tk'
    def button_callback
    p root.ip_eval("info globals")
    root.ip_eval("puts $tcl_version") #problem
    end
    root=3DTk.root
    button=3DTkButton.new(root){
    command proc{button_callback}
    }
    button.pack
    root.mainloop
    ########################

    The interpreter responds with:
    RuntimeError: can't read "tcl_version": no such variable
    Calling "info globals" gives "tcl_version" as an existing global variable

    The (almost) equivalent python code works:
    #test.py################
    from Tkinter import *
    def button_callback():
    print root.tk.eval("info globals")
    root.tk.eval("puts $tcl_version")
    root=3DTk()
    button=3DButton(root)
    button["command"]=3D button_callback
    button.pack()
    root.mainloop()
    ########################

    Thanks.
     
    Bojan Petrovic, Dec 2, 2005
    #1
    1. Advertising

  2. From: "Bojan Petrovic" <>
    Subject: Accessing tcl/tk global variables from callbacks
    Date: Sat, 3 Dec 2005 05:43:04 +0900
    Message-ID: <>
    > def button_callback
    > p root.ip_eval("info globals")
    > root.ip_eval("puts $tcl_version") #problem
    > end


    root.ip_eval('global tcl_version; puts $tcl_version')

    or

    root.ip_eval('puts $::tcl_version')

    --
    Hidetoshi NAGAI ()
     
    Hidetoshi NAGAI, Dec 3, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    3,370
  2. Bill Medland
    Replies:
    1
    Views:
    873
    Gordon Beaton
    Sep 29, 2006
  3. iwl
    Replies:
    3
    Views:
    660
  4. Sergey Polyakov

    Accessing request params during callbacks (ASP.Net 2.0)

    Sergey Polyakov, May 31, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    124
    Sergey Polyakov
    May 31, 2005
  5. Mumia W.

    Inline::Tcl vs. Inline::Tcl

    Mumia W., Aug 23, 2006, in forum: Perl Misc
    Replies:
    0
    Views:
    142
    Mumia W.
    Aug 23, 2006
Loading...

Share This Page