def __init__(self,parent=none)frame __init__(self,parentself pack(label(selftext ="basic demos"pack(button(selftext='open'command=self openfilepack(fill=bothbutton(selftext='save'command=self savefilepack(fill=bothself open_name self save_name "def openfile(self)save user results self open_name askopenfilename(use dialog options here def savefile(self)self save_name asksaveasfilename(initialdir=' :\\python 'if __name__ ="__main__"display window once print('popup 'mydialog demo(attaches frame to default tk(mydialog mainloop(displayreturns after windows closed print(mydialog open_namenames still on objectthough gui gone print(mydialog save_namenon gui section of the program uses mydialog here display window again print('popup 'mydialog demo(re-create widgets again mydialog mainloop(window pops up again print(mydialog open_namenew values on the object again print(mydialog save_namenon gui section of the program uses mydialog again print('ending 'this program twice builds and displays simple two-button main window that launches file selection dialogsshown in figure - its outputprinted as the gui windows are closedlooks like thisc:\pp \gui\toolsmainloopdemo py popup :/users/mark/stuff/books/ /pp /dev/examples/pp /gui/tools/widgets py :/python /python exe popup :/users/mark/stuff/books/ /pp /dev/examples/pp /gui/tools/guimixin py :/python /lib/tkinter/__init__ py ending notice how this program calls mainloop twiceto implement two modal user interactions from an otherwise non-gui script it' ok to call mainloop more than oncebut this script takes care to re-create the gui' widgets before each call because they are destroyed when the previous mainloop call exits (widgets are destroyed internally inside tkeven though the corresponding python widget object still existsagainthis can make for an odd user experience compared to traditional gui program structure-windows seem to pop up from nowhere--but it' quick way to put gui face on script without reworking its code gui coding techniques