File Transfer Need Help

ADE n/a
Sat Jul 24 08:14:50 CEST 2004

Hi everyone well from my last post I found what I am looking for

I have some code now that transfers files

I have added a GUI to it and need some help with two things one my
loadtemplate() function if I run it won't open the filetypes I just get the
error message from tkMessageBox but its the right filetype

and the final problem the Variable FILE how can I get it to interact with
GUI once I select an image to send how can I use the selected File to send
using the sendfile function

this is as far as I know the last of my problems

please note that this code has been taken from different parts of the


# USAGE: python [file]
from Tkinter import *
import tkFileDialog
import tkMessageBox
import sys, socket

root = Tk()
root.title("My APP")
root.minsize(300, 200)
root.maxsize(500, 400)

def loadtemplate():
    filename = tkFileDialog.askopenfilename(filetypes=(("TIFF", ".tiff"),
                                                       ("JPG", ".jpg"),
                                                       ("GIF", ".gif")))
    if filename:
            tkMessageBox.showerror("Open Source File", "Failed to read file
\n'%s' " %filename)

HOST = 'localhost'
CPORT = 9091
MPORT = 9090
FILE = # I need help here what do I put here

def sendfile():
    cs = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    cs.connect((HOST, CPORT))
    cs.send("SEND " + FILE)

    ms = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    ms.connect((HOST, MPORT))

    f = open(FILE, "rb")
    data =
    textbox.insert("Sending File Now...")
    textbox.insert("File Sent now Closing")

mybrowse = Button(root, text="Browse", command=loadtemplate)
mybrowse.grid(row=0, column=0, sticky=E+W)
mybutton = Button(root, text="Send File", command=sendfile)
mybutton.grid(row=0, column=1, sticky=E+W)
textbox = Text(root)
textbox.grid(row=1, column=0, columnspan=2)
textbox.insert(END, "Depending on size of File this could take a while\n\n")

More information about the Python-list mailing list