Forum: Ruby Accessing tcl/tk global variables from callbacks

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
bpetrovi (Guest)
on 2005-12-02 22:45
(Received via mailing list)
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=Tk.root
button=TkButton.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=Tk()
button=Button(root)
button["command"]= button_callback
button.pack()
root.mainloop()
########################

Thanks.
nagai (Guest)
on 2005-12-03 09:57
(Received via mailing list)
From: "Bojan Petrovic" <removed_email_address@domain.invalid>
Subject: Accessing tcl/tk global variables from callbacks
Date: Sat, 3 Dec 2005 05:43:04 +0900
Message-ID: <removed_email_address@domain.invalid>
> 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')
This topic is locked and can not be replied to.