Skip to content

Biostumblematic

A biophysicist teaches himself how to code

As I was casting about for something simple to do to expand my knowledge, I decided I’d try to create a simple GUI to the PDBcleaner. This is in preparation for expanding its capabilities a bit.

I’ve run into one of those frustrating brick walls. It’s annoying because I’m sure that the answer is simple and I’m just not “getting it”.

I’ve got a series of buttons. The first two call up file selection dialogs and allow the user to pick the input and output files. The third one should run the script; that is read in the input, do things, write the output.

I can’t seem to figure out how to pass the filename values from the first two functions (file selection) to the third function (run).

Here is the non-working code:

    def askopenfilename(dirtyfile):
        dirtyfile = tkFileDialog.askopenfilename()
        return dirtyfile

    def asksaveasfilename(cleanfile):
        cleanfile = tkFileDialog.asksaveasfilename()
        return cleanfile

    def run(self):
        atomrecords=[]
	inputfile = open(dirtyfile, 'r')

When we hit that last line I get an error that the global name “dirtyfile” is not defined. I’ve tried various ways to pass these variables and haven’t met with any success.

I feel like the answer lies in the arguments for the functions, but my google-fu seems to be weak and I can’t find the key nugget of information to get me over this hump. Maybe I just need to take a short break to dislodge the blockage.

Advertisements

Tags: , ,

%d bloggers like this: