tkinter call backs

Gordon Williams g_will at cyberus.ca
Mon Jul 19 12:18:58 EDT 1999


I have a simple problem that I cant find the solution.  I have a menu item
to open a file which has a command "openfile".  I would like to activate
"tkFileDialog.askopenfilename" to get the name of the file.  This requires
"parent=root" or something like that for the position of the message box.

How do I pass "root" into openfile?  

Thanks
Gordon Williams



def openfile():
    print "opening file"
    fileName=tkFileDialog.askopenfilename(parent=root, title="Open")
    if fileName:    #checks for cancel
        print fileName  #name of file to open
        file=open(fileName, 'r')
        read='junk' #initialize read with something
        while read != "":
            read=file.readline()
            print "number1",read[0:-1] # strips off line return character
#       This has one more line than needed due to EOF line.
#       Will use seek() to move to 2nd line
        print "number of bytes ",file.tell()
        file.close()




More information about the Python-list mailing list