文件操作 - easygui_pydoc.html
返回文件管理
返回主菜单
删除本文件
文件: /usr/share/doc/python2-easygui-0.96/pydoc/easygui_pydoc.html
编辑文件内容
<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><title>Python: module easygui</title> </head><body bgcolor="#f0f0f8"> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> <tr bgcolor="#7799ee"> <td valign=bottom> <br> <font color="#ffffff" face="helvetica, arial"> <br><big><big><strong>easygui</strong></big></big></font></td ><td align=right valign=bottom ><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:///C|/pydev/easygui/current_version/easygui.py">c:\pydev\easygui\current_version\easygui.py</a></font></td></tr></table> <p><tt>@version: 0.96(2010-06-25)<br> @note:<br> EasyGui provides an easy-to-use interface for simple GUI interaction<br> with a user. It does not require the programmer to know anything about<br> tkinter, frames, widgets, callbacks or lambda. All GUI interactions are<br> invoked by simple function calls that return results.<br> <br> <br> @note:<br> WARNING about using EasyGui with IDLE<br> <br> You may encounter problems using IDLE to run programs that use EasyGui. Try it<br> and find out. EasyGui is a collection of Tkinter routines that run their own<br> event loops. IDLE is also a Tkinter application, with its own event loop. The<br> two may conflict, with unpredictable results. If you find that you have<br> problems, try running your EasyGui program outside of IDLE.<br> <br> Note that EasyGui requires Tk release 8.0 or greater.</tt></p> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#aa55cc"> <td colspan=3 valign=bottom> <br> <font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr> <tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td> <td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="FixTk.html">FixTk</a><br> <a href="os.html">os</a><br> <a href="pickle.html">pickle</a><br> </td><td width="25%" valign=top><a href="pprint.html">pprint</a><br> <a href="string.html">string</a><br> <a href="sys.html">sys</a><br> </td><td width="25%" valign=top><a href="tkFileDialog.html">tkFileDialog</a><br> <a href="_tkinter.html">_tkinter</a><br> <a href="traceback.html">traceback</a><br> </td><td width="25%" valign=top><a href="types.html">types</a><br> </td></tr></table></td></tr></table><p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ee77aa"> <td colspan=3 valign=bottom> <br> <font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr> <tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td> <td width="100%"><dl> <dt><font face="helvetica, arial"><a href="easygui.html#EgStore">EgStore</a> </font></dt></dl> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom> <br> <font color="#000000" face="helvetica, arial"><a name="EgStore">class <strong>EgStore</strong></a></font></td></tr> <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> <td colspan=2><tt>A class to support persistent storage.<br> <br> You can use <a href="#EgStore">EgStore</a> to support the storage and retrieval<br> of user settings for an EasyGui application.<br> <br> <br> # Example A<br> #-----------------------------------------------------------------------<br> # define a class named Settings as a subclass of <a href="#EgStore">EgStore</a><br> #-----------------------------------------------------------------------<br> class Settings(<a href="#EgStore">EgStore</a>):<br> <br> def <a href="#EgStore-__init__">__init__</a>(self, filename): # filename is required<br> #-------------------------------------------------<br> # Specify default/initial values for variables that<br> # this particular application wants to remember.<br> #-------------------------------------------------<br> self.<strong>userId</strong> = ""<br> self.<strong>targetServer</strong> = ""<br> <br> #-------------------------------------------------<br> # For subclasses of <a href="#EgStore">EgStore</a>, these must be<br> # the last two statements in __init__<br> #-------------------------------------------------<br> self.<strong>filename</strong> = filename # this is required<br> <a href="#EgStore-restore">restore</a>() # restore values from the storage file if possible<br> <br> <br> <br> # Example B<br> #-----------------------------------------------------------------------<br> # create settings, a persistent Settings object<br> #-----------------------------------------------------------------------<br> settingsFile = "myApp_settings.txt"<br> settings = Settings(settingsFile)<br> <br> user = "obama_barak"<br> server = "whitehouse1"<br> settings.userId = user<br> settings.targetServer = server<br> settings.<a href="#EgStore-store">store</a>() # persist the settings<br> <br> # run code that gets a new value for userId, and persist the settings<br> user = "biden_joe"<br> settings.userId = user<br> settings.<a href="#EgStore-store">store</a>()<br> <br> <br> # Example C<br> #-----------------------------------------------------------------------<br> # recover the Settings instance, change an attribute, and store it again.<br> #-----------------------------------------------------------------------<br> settings = Settings(settingsFile)<br> settings.userId = "vanrossum_g"<br> settings.<a href="#EgStore-store">store</a>()<br> </tt></td></tr> <tr><td> </td> <td width="100%">Methods defined here:<br> <dl><dt><a name="EgStore-__init__"><strong>__init__</strong></a>(self, filename)</dt></dl> <dl><dt><a name="EgStore-__str__"><strong>__str__</strong></a>(self)</dt><dd><tt>return my contents as a string in an easy-to-read format.</tt></dd></dl> <dl><dt><a name="EgStore-kill"><strong>kill</strong></a>(self)</dt><dd><tt>Delete my persistent file (i.e. pickle file), if it exists.</tt></dd></dl> <dl><dt><a name="EgStore-restore"><strong>restore</strong></a>(self)</dt><dd><tt>Set the values of whatever attributes are recoverable<br> from the pickle file.<br> <br> Populate the attributes (the __dict__) of the <a href="#EgStore">EgStore</a> object<br> from the attributes (the __dict__) of the pickled object.<br> <br> If the pickled object has attributes that have been initialized<br> in the <a href="#EgStore">EgStore</a> object, then those attributes of the <a href="#EgStore">EgStore</a> object<br> will be replaced by the values of the corresponding attributes<br> in the pickled object.<br> <br> If the pickled object is missing some attributes that have<br> been initialized in the <a href="#EgStore">EgStore</a> object, then those attributes<br> of the <a href="#EgStore">EgStore</a> object will retain the values that they were<br> initialized with.<br> <br> If the pickled object has some attributes that were not<br> initialized in the <a href="#EgStore">EgStore</a> object, then those attributes<br> will be ignored.<br> <br> IN SUMMARY:<br> <br> After the recover() operation, the <a href="#EgStore">EgStore</a> object will have all,<br> and only, the attributes that it had when it was initialized.<br> <br> Where possible, those attributes will have values recovered<br> from the pickled object.</tt></dd></dl> <dl><dt><a name="EgStore-store"><strong>store</strong></a>(self)</dt><dd><tt>Save the attributes of the <a href="#EgStore">EgStore</a> object to a pickle file.<br> Note that if the directory for the pickle file does not already exist,<br> the store operation will fail.</tt></dd></dl> </td></tr></table></td></tr></table><p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#eeaa77"> <td colspan=3 valign=bottom> <br> <font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr> <tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td> <td width="100%"><dl><dt><a name="-abouteasygui"><strong>abouteasygui</strong></a>()</dt><dd><tt>shows the easygui revision history</tt></dd></dl> <dl><dt><a name="-boolbox"><strong>boolbox</strong></a>(msg<font color="#909090">='Shall I continue?'</font>, title<font color="#909090">=' '</font>, choices<font color="#909090">=('Yes', 'No')</font>, image<font color="#909090">=None</font>)</dt><dd><tt>Display a boolean msgbox.<br> <br> The default is the first choice.<br> <br> The returned value is calculated this way::<br> if the first choice is chosen, or if the dialog is cancelled:<br> returns 1<br> else:<br> returns 0</tt></dd></dl> <dl><dt><a name="-buttonbox"><strong>buttonbox</strong></a>(msg<font color="#909090">=''</font>, title<font color="#909090">=' '</font>, choices<font color="#909090">=('Button1', 'Button2', 'Button3')</font>, image<font color="#909090">=None</font>, root<font color="#909090">=None</font>)</dt><dd><tt>Display a msg, a title, and a set of buttons.<br> The buttons are defined by the members of the choices list.<br> Return the text of the button that the user selected.<br> <br> @arg msg: the msg to be displayed.<br> @arg title: the window title<br> @arg choices: a list or tuple of the choices to be displayed</tt></dd></dl> <dl><dt><a name="-ccbox"><strong>ccbox</strong></a>(msg<font color="#909090">='Shall I continue?'</font>, title<font color="#909090">=' '</font>, choices<font color="#909090">=('Continue', 'Cancel')</font>, image<font color="#909090">=None</font>)</dt><dd><tt>Display a msgbox with choices of Continue and Cancel.<br> <br> The default is "Continue".<br> <br> The returned value is calculated this way::<br> if the first choice ("Continue") is chosen, or if the dialog is cancelled:<br> return 1<br> else:<br> return 0<br> <br> If invoked without a msg argument, displays a generic request for a confirmation<br> that the user wishes to continue. So it can be used this way::<br> <br> if <a href="#-ccbox">ccbox</a>():<br> pass # continue<br> else:<br> sys.exit(0) # exit the program<br> <br> @arg msg: the msg to be displayed.<br> @arg title: the window title<br> @arg choices: a list or tuple of the choices to be displayed</tt></dd></dl> <dl><dt><a name="-choicebox"><strong>choicebox</strong></a>(msg<font color="#909090">='Pick something.'</font>, title<font color="#909090">=' '</font>, choices<font color="#909090">=()</font>)</dt><dd><tt>Present the user with a list of choices.<br> return the choice that he selects.<br> return None if he cancels the selection selection.<br> <br> @arg msg: the msg to be displayed.<br> @arg title: the window title<br> @arg choices: a list or tuple of the choices to be displayed</tt></dd></dl> <dl><dt><a name="-codebox"><strong>codebox</strong></a>(msg<font color="#909090">=''</font>, title<font color="#909090">=' '</font>, text<font color="#909090">=''</font>)</dt><dd><tt>Display some text in a monospaced font, with no line wrapping.<br> This function is suitable for displaying code and text that is<br> formatted using spaces.<br> <br> The text parameter should be a string, or a list or tuple of lines to be<br> displayed in the textbox.</tt></dd></dl> <dl><dt><a name="-diropenbox"><strong>diropenbox</strong></a>(msg<font color="#909090">=None</font>, title<font color="#909090">=None</font>, default<font color="#909090">=None</font>)</dt><dd><tt>A dialog to get a directory name.<br> Note that the msg argument, if specified, is ignored.<br> <br> Returns the name of a directory, or None if user chose to cancel.<br> <br> If the "default" argument specifies a directory name, and that<br> directory exists, then the dialog box will start with that directory.</tt></dd></dl> <dl><dt><a name="-egdemo"><strong>egdemo</strong></a>()</dt><dd><tt>Run the EasyGui demo.</tt></dd></dl> <dl><dt><a name="-enterbox"><strong>enterbox</strong></a>(msg<font color="#909090">='Enter something.'</font>, title<font color="#909090">=' '</font>, default<font color="#909090">=''</font>, strip<font color="#909090">=True</font>, image<font color="#909090">=None</font>, root<font color="#909090">=None</font>)</dt><dd><tt>Show a box in which a user can enter some text.<br> <br> You may optionally specify some default text, which will appear in the<br> enterbox when it is displayed.<br> <br> Returns the text that the user entered, or None if he cancels the operation.<br> <br> By default, enterbox strips its result (i.e. removes leading and trailing<br> whitespace). (If you want it not to strip, use keyword argument: strip=False.)<br> This makes it easier to test the results of the call::<br> <br> reply = <a href="#-enterbox">enterbox</a>(....)<br> if reply:<br> ...<br> else:<br> ...</tt></dd></dl> <dl><dt><a name="-exceptionbox"><strong>exceptionbox</strong></a>(msg<font color="#909090">=None</font>, title<font color="#909090">=None</font>)</dt><dd><tt>Display a box that gives information about<br> an exception that has just been raised.<br> <br> The caller may optionally pass in a title for the window, or a<br> msg to accompany the error information.<br> <br> Note that you do not need to (and cannot) pass an exception object<br> as an argument. The latest exception will automatically be used.</tt></dd></dl> <dl><dt><a name="-fileopenbox"><strong>fileopenbox</strong></a>(msg<font color="#909090">=None</font>, title<font color="#909090">=None</font>, default<font color="#909090">='*'</font>, filetypes<font color="#909090">=None</font>)</dt><dd><tt>A dialog to get a file name.<br> <br> About the "default" argument<br> ============================<br> The "default" argument specifies a filepath that (normally)<br> contains one or more wildcards.<br> fileopenbox will display only files that match the default filepath.<br> If omitted, defaults to "*" (all files in the current directory).<br> <br> WINDOWS EXAMPLE::<br> ...default="c:/myjunk/*.py"<br> will open in directory c:\myjunk\ and show all Python files.<br> <br> WINDOWS EXAMPLE::<br> ...default="c:/myjunk/test*.py"<br> will open in directory c:\myjunk\ and show all Python files<br> whose names begin with "test".<br> <br> <br> Note that on Windows, fileopenbox automatically changes the path<br> separator to the Windows path separator (backslash).<br> <br> About the "filetypes" argument<br> ==============================<br> If specified, it should contain a list of items,<br> where each item is either::<br> - a string containing a filemask # e.g. "*.txt"<br> - a list of strings, where all of the strings except the last one<br> are filemasks (each beginning with "*.",<br> such as "*.txt" for text files, "*.py" for Python files, etc.).<br> and the last string contains a filetype description<br> <br> EXAMPLE::<br> filetypes = ["*.css", ["*.htm", "*.html", "HTML files"] ]<br> <br> NOTE THAT<br> =========<br> <br> If the filetypes list does not contain ("All files","*"),<br> it will be added.<br> <br> If the filetypes list does not contain a filemask that includes<br> the extension of the "default" argument, it will be added.<br> For example, if default="*abc.py"<br> and no filetypes argument was specified, then<br> "*.py" will automatically be added to the filetypes argument.<br> <br> @rtype: string or None<br> @return: the name of a file, or None if user chose to cancel<br> <br> @arg msg: the msg to be displayed.<br> @arg title: the window title<br> @arg default: filepath with wildcards<br> @arg filetypes: filemasks that a user can choose, e.g. "*.txt"</tt></dd></dl> <dl><dt><a name="-filesavebox"><strong>filesavebox</strong></a>(msg<font color="#909090">=None</font>, title<font color="#909090">=None</font>, default<font color="#909090">=''</font>, filetypes<font color="#909090">=None</font>)</dt><dd><tt>A file to get the name of a file to save.<br> Returns the name of a file, or None if user chose to cancel.<br> <br> The "default" argument should contain a filename (i.e. the<br> current name of the file to be saved). It may also be empty,<br> or contain a filemask that includes wildcards.<br> <br> The "filetypes" argument works like the "filetypes" argument to<br> fileopenbox.</tt></dd></dl> <dl><dt><a name="-indexbox"><strong>indexbox</strong></a>(msg<font color="#909090">='Shall I continue?'</font>, title<font color="#909090">=' '</font>, choices<font color="#909090">=('Yes', 'No')</font>, image<font color="#909090">=None</font>)</dt><dd><tt>Display a buttonbox with the specified choices.<br> Return the index of the choice selected.</tt></dd></dl> <dl><dt><a name="-integerbox"><strong>integerbox</strong></a>(msg<font color="#909090">=''</font>, title<font color="#909090">=' '</font>, default<font color="#909090">=''</font>, lowerbound<font color="#909090">=0</font>, upperbound<font color="#909090">=99</font>, image<font color="#909090">=None</font>, root<font color="#909090">=None</font>, **invalidKeywordArguments)</dt><dd><tt>Show a box in which a user can enter an integer.<br> <br> In addition to arguments for msg and title, this function accepts<br> integer arguments for "default", "lowerbound", and "upperbound".<br> <br> The default argument may be None.<br> <br> When the user enters some text, the text is checked to verify that it<br> can be converted to an integer between the lowerbound and upperbound.<br> <br> If it can be, the integer (not the text) is returned.<br> <br> If it cannot, then an error msg is displayed, and the integerbox is<br> redisplayed.<br> <br> If the user cancels the operation, None is returned.<br> <br> NOTE that the "argLowerBound" and "argUpperBound" arguments are no longer<br> supported. They have been replaced by "upperbound" and "lowerbound".</tt></dd></dl> <dl><dt><a name="-msgbox"><strong>msgbox</strong></a>(msg<font color="#909090">='(Your message goes here)'</font>, title<font color="#909090">=' '</font>, ok_button<font color="#909090">='OK'</font>, image<font color="#909090">=None</font>, root<font color="#909090">=None</font>)</dt><dd><tt>Display a messagebox</tt></dd></dl> <dl><dt><a name="-multchoicebox"><strong>multchoicebox</strong></a>(msg<font color="#909090">='Pick as many items as you like.'</font>, title<font color="#909090">=' '</font>, choices<font color="#909090">=()</font>, **kwargs)</dt><dd><tt>Present the user with a list of choices.<br> allow him to select multiple items and return them in a list.<br> if the user doesn't choose anything from the list, return the empty list.<br> return None if he cancelled selection.<br> <br> @arg msg: the msg to be displayed.<br> @arg title: the window title<br> @arg choices: a list or tuple of the choices to be displayed</tt></dd></dl> <dl><dt><a name="-multenterbox"><strong>multenterbox</strong></a>(msg<font color="#909090">='Fill in values for the fields.'</font>, title<font color="#909090">=' '</font>, fields<font color="#909090">=()</font>, values<font color="#909090">=()</font>)</dt><dd><tt>Show screen with multiple data entry fields.<br> <br> If there are fewer values than names, the list of values is padded with<br> empty strings until the number of values is the same as the number of names.<br> <br> If there are more values than names, the list of values<br> is truncated so that there are as many values as names.<br> <br> Returns a list of the values of the fields,<br> or None if the user cancels the operation.<br> <br> Here is some example code, that shows how values returned from<br> multenterbox can be checked for validity before they are accepted::<br> ----------------------------------------------------------------------<br> msg = "Enter your personal information"<br> title = "Credit Card Application"<br> fieldNames = ["Name","Street Address","City","State","ZipCode"]<br> fieldValues = [] # we start with blanks for the values<br> fieldValues = <a href="#-multenterbox">multenterbox</a>(msg,title, fieldNames)<br> <br> # make sure that none of the fields was left blank<br> while 1:<br> if fieldValues == None: break<br> errmsg = ""<br> for i in range(len(fieldNames)):<br> if fieldValues[i].strip() == "":<br> errmsg += ('"%s" is a required field.\n\n' % fieldNames[i])<br> if errmsg == "":<br> break # no problems found<br> fieldValues = <a href="#-multenterbox">multenterbox</a>(errmsg, title, fieldNames, fieldValues)<br> <br> writeln("Reply was: %s" % str(fieldValues))<br> ----------------------------------------------------------------------<br> <br> @arg msg: the msg to be displayed.<br> @arg title: the window title<br> @arg fields: a list of fieldnames.<br> @arg values: a list of field values</tt></dd></dl> <dl><dt><a name="-multpasswordbox"><strong>multpasswordbox</strong></a>(msg<font color="#909090">='Fill in values for the fields.'</font>, title<font color="#909090">=' '</font>, fields<font color="#909090">=()</font>, values<font color="#909090">=()</font>)</dt><dd><tt>Same interface as multenterbox. But in multpassword box,<br> the last of the fields is assumed to be a password, and<br> is masked with asterisks.<br> <br> Example<br> =======<br> <br> Here is some example code, that shows how values returned from<br> multpasswordbox can be checked for validity before they are accepted::<br> msg = "Enter logon information"<br> title = "Demo of multpasswordbox"<br> fieldNames = ["Server ID", "User ID", "Password"]<br> fieldValues = [] # we start with blanks for the values<br> fieldValues = <a href="#-multpasswordbox">multpasswordbox</a>(msg,title, fieldNames)<br> <br> # make sure that none of the fields was left blank<br> while 1:<br> if fieldValues == None: break<br> errmsg = ""<br> for i in range(len(fieldNames)):<br> if fieldValues[i].strip() == "":<br> errmsg = errmsg + ('"%s" is a required field.\n\n' % fieldNames[i])<br> if errmsg == "": break # no problems found<br> fieldValues = <a href="#-multpasswordbox">multpasswordbox</a>(errmsg, title, fieldNames, fieldValues)<br> <br> writeln("Reply was: %s" % str(fieldValues))</tt></dd></dl> <dl><dt><a name="-passwordbox"><strong>passwordbox</strong></a>(msg<font color="#909090">='Enter your password.'</font>, title<font color="#909090">=' '</font>, default<font color="#909090">=''</font>, image<font color="#909090">=None</font>, root<font color="#909090">=None</font>)</dt><dd><tt>Show a box in which a user can enter a password.<br> The text is masked with asterisks, so the password is not displayed.<br> Returns the text that the user entered, or None if he cancels the operation.</tt></dd></dl> <dl><dt><a name="-textbox"><strong>textbox</strong></a>(msg<font color="#909090">=''</font>, title<font color="#909090">=' '</font>, text<font color="#909090">=''</font>, codebox<font color="#909090">=0</font>)</dt><dd><tt>Display some text in a proportional font with line wrapping at word breaks.<br> This function is suitable for displaying general written text.<br> <br> The text parameter should be a string, or a list or tuple of lines to be<br> displayed in the textbox.</tt></dd></dl> <dl><dt><a name="-ynbox"><strong>ynbox</strong></a>(msg<font color="#909090">='Shall I continue?'</font>, title<font color="#909090">=' '</font>, choices<font color="#909090">=('Yes', 'No')</font>, image<font color="#909090">=None</font>)</dt><dd><tt>Display a msgbox with choices of Yes and No.<br> <br> The default is "Yes".<br> <br> The returned value is calculated this way::<br> if the first choice ("Yes") is chosen, or if the dialog is cancelled:<br> return 1<br> else:<br> return 0<br> <br> If invoked without a msg argument, displays a generic request for a confirmation<br> that the user wishes to continue. So it can be used this way::<br> if <a href="#-ynbox">ynbox</a>(): pass # continue<br> else: sys.exit(0) # exit the program<br> <br> @arg msg: the msg to be displayed.<br> @arg title: the window title<br> @arg choices: a list or tuple of the choices to be displayed</tt></dd></dl> </td></tr></table><p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#55aa55"> <td colspan=3 valign=bottom> <br> <font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr> <tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td> <td width="100%"><strong>__all__</strong> = ['ynbox', 'ccbox', 'boolbox', 'indexbox', 'msgbox', 'buttonbox', 'integerbox', 'multenterbox', 'enterbox', 'exceptionbox', 'choicebox', 'codebox', 'textbox', 'diropenbox', 'fileopenbox', 'filesavebox', 'passwordbox', 'multpasswordbox', 'multchoicebox', 'abouteasygui', ...]<br> <strong>egversion</strong> = '0.96(2010-06-25)'</td></tr></table> </body></html>
修改文件时间
将文件时间修改为当前时间的前一年
删除文件