Example 14-6. PP4E\Internet\Email\PyMailGui\popuputil.py
"""
#############################################################################
utility windows - may be useful in other programs
#############################################################################
"""
from tkinter import *
from PP4E.Gui.Tools.windows import PopupWindow
class HelpPopup(PopupWindow):
"""
custom Toplevel that shows help text as scrolled text
source button runs a passed-in callback handler
3.0 alternative: use HTML file and webbrowser module
"""
myfont = 'system' # customizable
mywidth = 78 # 3.0: start width
def init(self, appname, helptext, iconfile=None, showsource=lambda:0):
PopupWindow.init(self, appname, 'Help', iconfile)
from tkinter.scrolledtext import ScrolledText # a nonmodal dialog
bar = Frame(self) # pack first=clip last
bar.pack(side=BOTTOM, fill=X)
code = Button(bar, bg='beige', text="Source", command=showsource)
quit = Button(bar, bg='beige', text="Cancel", command=self.destroy)
code.pack(pady=1, side=LEFT)
quit.pack(pady=1, side=LEFT)
text = ScrolledText(self) # add Text + scrollbar
text.config(font=self.myfont)
text.config(width=self.mywidth) # too big for showinfo
text.config(bg='steelblue', fg='white') # erase on btn or return
text.insert('0.0', helptext)
text.pack(expand=YES, fill=BOTH)
self.bind("
def askPasswordWindow(appname, prompt):
"""
modal dialog to input password string
getpass.getpass uses stdin, not GUI
tkSimpleDialog.askstring echos input
"""
win = PopupWindow(appname, 'Prompt') # a configured Toplevel
Label(win, text=prompt).pack(side=LEFT)
entvar = StringVar(win)
ent = Entry(win, textvariable=entvar, show='') # display for input
ent.pack(side=RIGHT, expand=YES, fill=X)
ent.bind('
ent.focus_set(); win.grab_set(); win.wait_window()
win.update() # update forces redraw
return entvar.get() # ent widget is now gone
PyMailGUI Implementation| 1099