New Tkinter front-end for existing program

Posted 24 November 2009 - 10:04 AM

Hi all!

Yes, my first post on this forum, and I come to you as an inexperienced Python coder. Brief background on myself - I'm a hobby programmer, learnt GW & QBASIC back in the day, tried early VB, then kinda left it. Decided to get back into hobby programming, looked at all the languages available, and chose Python. Got a good book, been reading it for the last year on and off, a lot of it makes a lot of sense (especially as my OO experience was zero).

Anyway, onto the issue I've got now. I'm writing a utility program for work, which will take a CSV file in, re-arrange it, and write a new one out. This is currently done by an Excel macro, which is a bit naff as Excel has a funny habit of applying it's own "style" to the file. I've already written a working program that does it from the CLI (well, 2 actually - one OO-based, and one not). My issue is, that it needs a GUI really, as I won't be the one running it in real life. So I've opted for Tkinter, as it's included with Python, so only one install required on the destination machines. Anyway, the code for the program is here:

It's not ideal at present, as I need to include more exception handling (as it stands, if someone tries to import a non-CSV file, it'll crash in an ugly Python way. Well, I quite like it actually ). I've got the Tkinter part started, based on a simple tutorial - it's going to have 3 buttons: a load, a re-format, and a quit button. My big question, is how do I link the 2? So, when the user clicks the "re-format" button, it executes the program I've already written? Is it something to do with the 'mainloop()' part of the Tkinter program?

Replies To: New Tkinter front-end for existing program

Re: New Tkinter front-end for existing program

Posted 27 November 2009 - 05:49 PM

chemicalfan, on 24 Nov, 2009 - 09:04 AM, said:

Hi all!

Yes, my first post on this forum, and I come to you as an inexperienced Python coder. Brief background on myself - I'm a hobby programmer, learnt GW & QBASIC back in the day, tried early VB, then kinda left it. Decided to get back into hobby programming, looked at all the languages available, and chose Python. Got a good book, been reading it for the last year on and off, a lot of it makes a lot of sense (especially as my OO experience was zero).

Anyway, onto the issue I've got now. I'm writing a utility program for work, which will take a CSV file in, re-arrange it, and write a new one out. This is currently done by an Excel macro, which is a bit naff as Excel has a funny habit of applying it's own "style" to the file. I've already written a working program that does it from the CLI (well, 2 actually - one OO-based, and one not). My issue is, that it needs a GUI really, as I won't be the one running it in real life. So I've opted for Tkinter, as it's included with Python, so only one install required on the destination machines. Anyway, the code for the program is here:

It's not ideal at present, as I need to include more exception handling (as it stands, if someone tries to import a non-CSV file, it'll crash in an ugly Python way. Well, I quite like it actually ). I've got the Tkinter part started, based on a simple tutorial - it's going to have 3 buttons: a load, a re-format, and a quit button. My big question, is how do I link the 2? So, when the user clicks the "re-format" button, it executes the program I've already written? Is it something to do with the 'mainloop()' part of the Tkinter program?

Hey, hows it going?
Well, looking over your code...
I think this syntax is invalid => b.append(a[i])
you might want to use the sort method, or the 'sorted' builtin function

onto the class declaration, I'm not sure what your opening with 'open(sys.argv[1],'r')'
seems troublesome to me to call a function inside a class, but it might work...
I seem to have more success calling the function outside of the class after collecting the needed input

you'll need to find a way to reset the data for the re-format button to have something to work with
perhaps re-loading it will work...

Re: New Tkinter front-end for existing program

Hey, hows it going?
Well, looking over your code...
I think this syntax is invalid => b.append(a[i])
you might want to use the sort method, or the 'sorted' builtin function

onto the class declaration, I'm not sure what your opening with 'open(sys.argv[1],'r')'
seems troublesome to me to call a function inside a class, but it might work...
I seem to have more success calling the function outside of the class after collecting the needed input

you'll need to find a way to reset the data for the re-format button to have something to work with
perhaps re-loading it will work...

Hi there, thanks for your reply - I think you've misunderstood my question though! The code I posted is fully functional, it just doesn't have a GUI at present. The user has to enter the filename when invoking the interpreter, and the open(sys.argv) call picks this up. I've attempted to code the GUI onto it, and it's not quite as "modular" as I would have liked (in other words, I've ended up cutting and pasting my current code into new methods/classes of the Tkinter code. Anyway, the program now falls over with an "AttributeError: tkfilename" when hitting the re-format button, even after clicking the "Load File" button first, and selecting the appropriate file. I fear this might be a global variable/local variable issue. The new code is here - any ideas what the issue is?: