12.07.2015 Views

Tkinter reference: A GUI for Python

Tkinter reference: A GUI for Python

Tkinter reference: A GUI for Python

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

3.3 Colors3.4 FontsThere are two general ways to specify colors in <strong>Tkinter</strong>. You can use a string specifying the proportion of red, green, and blue in hexadecimaldigits:#rgb#rrggbb#rrrgggbbb#rrrrggggbbbbFour bits per colorEight bits per colorTwelve bits per colorSixteen bits per colorFor example, "#fff" is white, "#000000" is black, "#000fff000" is pure green,and "#00ffff" is pure cyan (green plus blue). You can also use any locally defined standard color name. The strings "white","black", "red", "green", "blue", "cyan", "yellow", and "magenta" will alsobe available. Others depending on your local installation.Depending on your plat<strong>for</strong>m, there may be up to three ways to specify type style. As a tuple whose first element is the font family, followed by a size in points,optionally followed by a string containing one or more of the style modifiers bold,italic, underline, and overstrike.Examples:("Helvetica", "16")("Times", "24", "bold italic")16-point Helvetica regular24-pt Times bold italic You can create a “font object” by importing the tkFont module and using its Fontclass constructor:import tkFontfont = tkFont.Font ( *options )where the options include:familysizeweightslantunderlineoverstrikeThe font family as a string.The font height as an integer in points. To get a font npixels high, use -n."bold" <strong>for</strong> boldface, "normal" <strong>for</strong> regular weight."italic" <strong>for</strong> italic, "roman" <strong>for</strong> unslanted.1 <strong>for</strong> underlined text, 0 <strong>for</strong> normal.1 <strong>for</strong> overstruck text, 0 <strong>for</strong> normal.For example, to get a 36-point bold Helvetica italic face:helv36 = tkFont.Font ( family="Helvetica", size=36,weight="bold" ) If you are running under the X Window System, you can use any of the X fontnames. For example, this font"-*-lucidatypewriter-medium-r-*-*-*-140-*-*-*-*-*-*"New Mexico Tech Computer Center <strong>Tkinter</strong> <strong>reference</strong>: Standard attributes Page 7

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!