refactoring for GUI with Tk