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.

Higher-level priorities take precedence over lower-level ones.See Standardizing appearance and the option database, below, <strong>for</strong> an overview of the optiondatabase. The syntax of the pattern argument to .option_add() is the same as theoption-pattern part of the resource specification line.For example, to get the effect of this resource specification line:*Button*font:times 24 boldyour application (self in this example) might include these lines:self.bigFont = tkFont.Font ( family="times", size=24,weight="bold" )self.option_add ( "*Button*font", self.bigFont )Any Button widgets created after executing these lines would default to bold Times 24font (unless overriden by a font option to the Button constructor).w.option_clear()This method removes all options from the <strong>Tkinter</strong> option database. This has the effect ofgoing back to all the default values.w.option_get ( name, className )Use this method to retrieve the current value of an option from the <strong>Tkinter</strong> optiondatabase. The first argument is the instance key and the second argument is the classkey. If there are any matches, it returns the value of the option that best matches. If thereare no matches, it returns "".Refer to the section on Standardizing appearance, below, <strong>for</strong> more on matching keys tooptions.w.option_readfile ( fileName, priority=None )As a convenience <strong>for</strong> user configuration, you can designate a named file where users canput their preferred options, using the same <strong>for</strong>mat as the .Xdefaults file. Then, whenyour application is initializing, you can pass that file’s name to this method, and theoptions from that file will be added to the database. If the file doesn’t exist, or its <strong>for</strong>matis invalid, this method will raise TclError.Refer to the section on Standardizing appearance, below, <strong>for</strong> an introduction to the optionsdatabase and the <strong>for</strong>mat of option files.w.quit()This method exits the main loop. See .mainloop(), above, <strong>for</strong> a discussion of mainloops.w.selection_clear()If w currently has a selection (such as a highlighted segment of text in an entry widget),clear that selection.w.selection_get()If w currently has a selection, this method returns the selected text. If there is no selection,it raises TclError.New Mexico Tech Computer Center <strong>Tkinter</strong> <strong>reference</strong>: Universal widget methods Page 65

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

Saved successfully!

Ooh no, something went wrong!