[Tutor] Tkinter Geometry Management and Other Basics

Alan Gauld alan.gauld at btinternet.com
Fri Mar 20 21:42:23 CET 2009


"Wayne Watson" <sierra_mtnview at sbcglobal.net> wrote

> I really don't want to spend weeks learning Tk/Tcl.

You shouldn't need to.
The Tk documentation is very easy to transfer to Tkinter:
Here is a sample from the official reference docs for Label
(found at: http://www.tcl.tk/man/tcl8.5/TkCmd/contents.htm):

        STANDARD OPTIONS
  -activebackground, activeBackground, Foreground
  -activeforeground, activeForeground, Background
  -anchor, anchor, Anchor
  ...
  -takefocus, takeFocus, TakeFocus
  -text, text, Text
  -textvariable, textVariable, Variable
  -underline, underline, Underline
  -wraplength, wrapLength, WrapLength
WIDGET-SPECIFIC OPTIONS
  -height, height, Height
  -state, state, State
  -width, width, Width

So you can use

Label( option = value)

for any of the listed options. If you want to see what values are 
possible,
just click onthe option, for example state gives:
------------------------------------------
Command-Line Name: -state
Database Name: state
Database Class: State
Specifies one of three states for the label: normal, active, or 
disabled.
In normal state the button is displayed using the foreground and 
background options.
In active state the label is displayed using the activeForeground and 
activeBackground options.
In the disabled state the disabledForeground andbackground options 
determine how the button is displayed.

-----------------------------------------

No real Tcl knowledge required. Just remember that in Tkinter you 
should
quote the value as a string, so:

lbl = Label(text = "My Label", state='disabled')

It really is quite easy. Too few Tkinter programmer shy away from the 
Tcl/Tk
sites because they think they need to know Tcl. Its not the case 90+% 
of the time.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 




More information about the Tutor mailing list