corresponding getfile command line and runs it with the os.system call we studied in
Part II.
Example 12-18. PP4E\Internet\Sockets\getfilegui-1.py
"""
launch getfile script client from simple tkinter GUI;
could also use os.fork+exec, os.spawnv (see Launcher);
windows: replace 'python' with 'start' if not on path;
"""
import sys, os
from tkinter import *
from tkinter.messagebox import showinfo
def onReturnKey():
cmdline = ('python getfile.py -mode client -file %s -port %s -host %s' %
(content['File'].get(),
content['Port'].get(),
content['Server'].get()))
os.system(cmdline)
showinfo('getfilegui-1', 'Download complete')
box = Tk()
labels = ['Server', 'Port', 'File']
content = {}
for label in labels:
row = Frame(box)
row.pack(fill=X)
Label(row, text=label, width=6).pack(side=LEFT)
entry = Entry(row)
entry.pack(side=RIGHT, expand=YES, fill=X)
content[label] = entry
box.title('getfilegui-1')
box.bind('
mainloop()
When run, this script creates the input form shown in Figure 12-1. Pressing the Enter
key (
getfile command line is finished, we get the verification pop up displayed in
Figure 12-2.
Figure 12-1. getfilegui-1 in action
844 | Chapter 12: Network Scripting