简体   繁体   中英

Unable to use pickAFile in TigerJython

In JES, I am able to use:

file=pickAFile() 

In TigerJython, however, I get the following error

NameError: name 'pickAFile' is not defined

What am I doing wrong here?

You are not doing anything wrong at all. The thing is that pickAFile() is not a standard function in Python. It is actually rather a function that JES has added for convenience, but which you probably will not find it in any other environment.

Since TigerJython and JES are both based on Jython, you can easily write a pickAFile() function on your own that uses Java's Swing. Here is a possible simple implementation (the pickAFile() found in JES might be a bit more complex, but this should get you started):

def pickAFile():
    from javax.swing import JFileChooser
    fc = JFileChooser()
    retVal = fc.showOpenDialog(None)
    if retVal == JFileChooser.APPROVE_OPTION:
        return fc.getSelectedFile()
    else:
        return None

Given that it is certainly a useful function, we might have to consider including it into our next update of TigerJython.

PS I would like to apologise for answering so late, I have just joined SO recently and was not aware of your question (I am one of the original authors of TigerJython).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM