Accessing tcl/tk global variables from callbacks

B

Bojan Petrovic

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.
 
H

Hidetoshi NAGAI

From: "Bojan Petrovic" <[email protected]>
Subject: Accessing tcl/tk global variables from callbacks
Date: Sat, 3 Dec 2005 05:43:04 +0900
Message-ID: said:
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')
 

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
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top