Tkinter Wiki   TranslateTcl UserPreferences
 
HelpContents FindPage Diffs Info Edit Subscribe XML Print View

In ?Tcl, a widget is created by invoking the widget command with the name of the new widget and any configuration parameters. In Python, a widget is created by calling the class with the name of the new widget's parent and any configuration parameters. "-name value" pairs in Tcl become "name=value" keyword arguments in Python

Tcl Python
button .t.b -text "Click Me" b = Button(t, text="click me")

Widgets have methods which may accept positional or keyword arguments. Many methods are shared by all widget types, while almost every widget has a few special methods.

Tcl Python
.t.b invoke b.invoke()
.t.e insert end {Sample Text}  e.inert("end", "Sample Text") 

Some widget methods have compound names, which are typically spelled with an underscore in Python and a space in Tcl
Tcl Python
.t.t tag add newtag 0.0 end tt.tag_add("newtag", 0.0, "end")

Some methods in Python are separate commands in Tcl:
Tcl Python
grid .t.b b.grid()

When a keyword or name in Tcl is a Python reserved word, append a "_" when using it as a keyword argument:
Tcl Python
grid .t.b -in .t.f b.grid(in_=f)

Some special values used in Tcl are defined as constants in Tkinter:
Tcl Python
pack .b -side left b.pack(side=Tkinter.LEFT)
b.pack(side="left")


PythonPowered