mirror of
https://github.com/python/cpython.git
synced 2025-07-18 16:55:20 +00:00
Be more careful about accessing attributes of the parent: if Tk has not been
initialized, this will be None, but the functions will still work (there will simply be a bogus parent on the screen). Allowing the parent to be None is useful when testing the functions from an interactive interpreter. Add an optional keyword paramter "show" to the _QueryString class; when given it is used to set the -show option to the entry widget. This allows passing show="*" or the like to askstring(), making it useful for requesting passwords/passphrases from the user. This closes SF bug #438517. Changed a docstring to be less font-lock-hostile.
This commit is contained in:
parent
22d35a7337
commit
6b04ffe9e5
1 changed files with 20 additions and 4 deletions
|
@ -68,8 +68,9 @@ class Dialog(Toplevel):
|
||||||
|
|
||||||
self.protocol("WM_DELETE_WINDOW", self.cancel)
|
self.protocol("WM_DELETE_WINDOW", self.cancel)
|
||||||
|
|
||||||
self.geometry("+%d+%d" % (parent.winfo_rootx()+50,
|
if self.parent is not None:
|
||||||
parent.winfo_rooty()+50))
|
self.geometry("+%d+%d" % (parent.winfo_rootx()+50,
|
||||||
|
parent.winfo_rooty()+50))
|
||||||
|
|
||||||
self.initial_focus.focus_set()
|
self.initial_focus.focus_set()
|
||||||
|
|
||||||
|
@ -95,7 +96,7 @@ class Dialog(Toplevel):
|
||||||
def buttonbox(self):
|
def buttonbox(self):
|
||||||
'''add standard button box.
|
'''add standard button box.
|
||||||
|
|
||||||
override if you don't want the standard buttons
|
override if you do not want the standard buttons
|
||||||
'''
|
'''
|
||||||
|
|
||||||
box = Frame(self)
|
box = Frame(self)
|
||||||
|
@ -129,7 +130,8 @@ class Dialog(Toplevel):
|
||||||
def cancel(self, event=None):
|
def cancel(self, event=None):
|
||||||
|
|
||||||
# put focus back to the parent window
|
# put focus back to the parent window
|
||||||
self.parent.focus_set()
|
if self.parent is not None:
|
||||||
|
self.parent.focus_set()
|
||||||
self.destroy()
|
self.destroy()
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -270,6 +272,20 @@ def askfloat(title, prompt, **kw):
|
||||||
return d.result
|
return d.result
|
||||||
|
|
||||||
class _QueryString(_QueryDialog):
|
class _QueryString(_QueryDialog):
|
||||||
|
def __init__(self, *args, **kw):
|
||||||
|
if kw.has_key("show"):
|
||||||
|
self.__show = kw["show"]
|
||||||
|
del kw["show"]
|
||||||
|
else:
|
||||||
|
self.__show = None
|
||||||
|
_QueryDialog.__init__(self, *args, **kw)
|
||||||
|
|
||||||
|
def body(self, master):
|
||||||
|
entry = _QueryDialog.body(self, master)
|
||||||
|
if self.__show is not None:
|
||||||
|
entry.configure(show=self.__show)
|
||||||
|
return entry
|
||||||
|
|
||||||
def getresult(self):
|
def getresult(self):
|
||||||
return self.entry.get()
|
return self.entry.get()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue