On Thu, Aug 23, 2018 at 11:59 PM Steve Barnes <gadgetst...@live.co.uk> wrote: > There are already 2 ways of turning a python program that uses argparse > into a GUI, (Gooey for wx & Quicken for QT IIRC), with minimal > modification. There are a lot of good arguments for teaching people to > use argparse and to write their code to be able to run from the command > line but there is not a mechanism that I am aware of for turning > argparse based code into a TK GUI this might be a fruitful area to look > at.
I started working on a project that does that a few years ago. It requires that you provide a function that takes an argparse.Namespace, and then it can make a GUI using tkinter. The code is on GitHub: https://github.com/codypiersall/cligui. The license is MIT. Example script using cligui: ``` # Makes a GUI appear. How fortunate! import argparse import cligui def get_parser(): """Create a parser that does all the best things.""" p = argparse.ArgumentParser(description='such a good program') p.add_argument('infile') p.add_argument('outfile') return p def do_the_best_things(args): """This does the best things. Note: "args" is an argparse.Namespace -- the thing you get back whenever you call argparse.ArgumentParser().parse_args(). """ print('got args', args) def main(): """This incredible function will make a GUI appear. Remarkable!""" p = get_parser() # call cligui.CliGui with the parser, and a function that takes an # argparse.Namespace as its argument. cligui.CliGui(p, do_the_best_things) if __name__ == '__main__': main() ``` For background: the goal was to be able to let my less-technical coworkers use scripts that I had written; but then I got a job elsewhere and stopped working on this. Cody _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/