Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the "tk.call" function do in Python/Tkinter?

Tags:

python

tkinter

I have seen call function in Python scripts, called as tk.call(), but I don't understand the meaning of the same. There is no documentation related to it too.

Can any one please explain about the functionality of call() function.

This is a simple example:

p.tk.call(p, 'put', color, '-to', 0, 0, p['width'], p['height']) 

The functionality of this function, where p is the PhotoImage widget.

like image 774
AB Abhi Avatar asked Feb 21 '15 09:02

AB Abhi


People also ask

What is Tk In Tkinter?

Tkinter is a Python package which comes with many functions and methods that can be used to create an application. In order to create a tkinter application, we generally create an instance of tkinter frame, i.e., Tk (). It helps to display the root window and manages all the other components of the tkinter application.

What is Tkinter call in Python?

tkinter (Python Package) This call (say, for example, creating a button widget), is implemented in the tkinterpackage, which is written in Python. This Python function will parse the commands and the arguments and convert them into a form that makes them look as if they had come from a Tk script instead of a Python script.

How to create a GUI using Tkinter in Python?

Creating a GUI using tkinter is an easy task. Apply the event Trigger on the widgets. Importing tkinter is same as importing any other module in the Python code. Note that the name of the module in Python 2.x is ‘Tkinter’ and in Python 3.x it is ‘tkinter’.

How does Tkinter work with TCL?

Show activity on this post. Tkinter works by starting a tcl/tk interpreter under the covers, and then translating tkinter commands into tcl/tk commands. The main window and this interpreter are intrinsically linked, and both are required for a tkinter application to work.


2 Answers

Tkinter isn't pure python. Underlying it is a live Tcl interpreter with an extension called "tk" loaded into the interpreter. Most Tkinter commands, methods and objects eventually wind up as invocations of tcl commands. For example, when you do something like:

root = tk.Tk()
f = tk.Frame(root)
b = tk.Button(f, text="Press me!")

... it gets translated into something (roughly) like this:

package require tk
frame .f
button .f.b -text "Press me!"

(note: Tkinter actually generates more complex names than .f and .f.b, but the concept is the same)

The call method is the interface to this underlying tcl interpreter. It allows you to construct a tcl command and ask the interpreter to run it. It is a bridge between python and tcl.

It is not typically used in application-level code, though it can be useful in the rare cases where the Tkinter wrapper around tcl/tk doesn't provide access to some feature supported by tcl/tk.

like image 147
Bryan Oakley Avatar answered Oct 16 '22 17:10

Bryan Oakley


Tk.call() is from the Tkinter module, and it can be used to execute tcl-based commands directly from a Tkinter widget. Example Tkinter command to get the user's OS:

root.tk.call('tk', 'windowingsystem')

Where windowingsystem is a feature from tcl.

As far as I know there is no official documentation for tk.call().

like image 5
Leafthecat Avatar answered Oct 16 '22 17:10

Leafthecat