代码地址:https://code.youkuaiyun.com/ranky2009/pythonsmallproject
本项目基于Python基础教程(第二版)中的项目9:文件共享2。对代码略做修改,使得代码能在Win7系统,python3.4.3版本上运行。
原文中使用的是wxpython工具包做的界面,本处采用python中自带的tkinter制作简单的界面
代码如下:
1. simple_gui_client.py
import tkinter as tk
from client import Client
import sys
class Application(tk.Frame):
def __init__(self, master=None, client=None):
tk.Frame.__init__(self, master)
self.text = 'File Sharing Client'
self.pack()
self.createWidgets()
self.client = client
def createWidgets(self):
self.httpurlEntry = tk.Entry(self)
self.httpurlEntry.pack()
self.hi_there = tk.Button(self)
self.hi_there["text"] = "Fetch"
self.hi_there["command"] = self.say_hi
self.hi_there.pack()
#self.hi_there.pack(side="top")
self.QUIT = tk.Button(self, text="QUIT", fg="red",
command=self.master.destroy)
self.QUIT.pack(side="bottom")
def say_hi(self):
text = self.httpurlEntry.get()
print(text)
self.client.do_fe