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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

16.3 Images in text widgetsYou can put an image or bitmap into a text widget. It is treated as a single characterwhose size is the natural size of the object. See Images and Bitmaps, above.Images are placed into the text widget by calling that widget’s .image_create()method. See below <strong>for</strong> the calling sequence and other methods <strong>for</strong> image manipulation.Images are manipulated by passing their name to methods on the text widget. You cangive <strong>Tkinter</strong> a name <strong>for</strong> an image, or you can just let <strong>Tkinter</strong> generate a default name <strong>for</strong>that image.16.4 Windows in text widgetsYou can put any <strong>Tkinter</strong> widget—even a frame containing other widgets—into a textwidget. For example, you can put a fully functional button or a set of radiobuttons intoa text widget.Use the .window_create() method on the text widget to add the embedded widget.Refer to Methods on text widgets, below, <strong>for</strong> the calling sequence and related methods.16.5 Tags in text widgetsThere are lots of ways to change both the appearance and functionality of the items in atext widget. For text, you can change the font, size, and color. Also, you can make text,widgets, or embedded images respond to keyboard or mouse actions.To control these appearance and functional features, you associate each feature with atag. You can then associate a tag with any number of pieces of text in the widget. The name of a tag can be any string that does not contain white space or periods. There is one special predefined tag called SEL. This is the region currently selected,if any. Since any character may be part of more than one tag, there is a tag stack that ordersall the tags. Entries are added at the end of the tag list, and later entries have priorityover earlier entries. So, <strong>for</strong> example, if there is a character c that is part of two taggedregions t 1 and t 2 , and t 1 is deeper in the tag stack than t 2 , and t 1 wants the text to begreen and t 2 wants it to be blue, c will be rendered in blue because t 2 has precedenceover t 1 . You can change the ordering of tags in the tag stack.Tags are created by using the .tag_add() method on the text widget. See Methods ontext widgets, below, <strong>for</strong> in<strong>for</strong>mation on this and related methods.New Mexico Tech Computer Center <strong>Tkinter</strong> <strong>reference</strong>: The Text widget Page 51

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

Saved successfully!

Ooh no, something went wrong!