modifed for tkinter