0

I'm using python tkinter to run tcl in python And there are two ways to run a tcl command:

import tkinter 
root = tkinter.Tk()
root.eval("winfo exists .l0")
root.tk.call("winfo exists .l0")

They have the same meaning

But what's different? And if I haven't define a widget names .l0 and can I directly use

child = ".l0"
child.winfo_exists()

? Because python told me "str has no attribute winfo_exists"

1 Answer 1

1

The difference is that call passes each argument to tcl as a separate word, where eval will evaluate a string by first parsing it and then executing it.

In other words, this:

root.eval("winfo exists .l0")

... is functionally identical to this:

root.tk.call("winfo", "exists", ".l0")

As for the error message 'str' object has no attribute 'winfo_exists', it means exactly that. "l0" is the name of an object in the embedded tcl interpreter, but in python "l0" is just a string and python strings don't have the attribute winfo_exists.

Sign up to request clarification or add additional context in comments.

4 Comments

if I need to test a window named .l0 without type of it, do you know how to deal with that?
@shuji: I don't understand your question. ".l0" doesn't have a type in the world of tcl. In tcl, everything is a string. I'm sure that what you want can be done, but I can't understand what you want.
what I mean is that, in wish(tcl shell), I can type "winfo exists .l0" but how can I do that in python? With .l0 an unknown widget(not a topleve, frame etc.)
@shuji: Like my answer shows, you can call root.tk.call and pass in whatever window name you want. That will only tell you if there is a tcl/tk window by that name, it won't tell you if a tkinter object representing that widget exists. This is a highly unusual thing to do, since with tkinter you almost never know the internal window name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.