[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1

like. Figure 12-5 shows the input form constructed in response to the following console
interaction. Field names could be accepted on the command line, too, but the input
built-in function works just as well for simple tests like this. In this mode, the GUI goes
away after the first submit, because DynamicForm.onSubmit says so:


C:\...\PP4E\Internet\Sockets> python form.py -
Enter field names: Name Email Web Locale
Field values...
Locale => Florida
Web => http://learning-python.com
Name => Book
Email => [email protected]

Figure 12-5. Form test, dynamic fields


And last but not least, Example 12-21 shows the getfile user interface again, this time
constructed with the reusable form layout class. We need to fill in only the form labels
list and provide an onSubmit callback method of our own. All of the work needed to
construct the form comes “for free,” from the imported and widely reusable Form
superclass.


Example 12-21. PP4E\Internet\Sockets\getfilegui.py


"""
launch getfile client with a reusable GUI form class;
os.chdir to target local dir if input (getfile stores in cwd);


Figure 12-4. Form test, canned fields


848 | Chapter 12: Network Scripting

Free download pdf