summaryrefslogtreecommitdiffstats
path: root/Lib/lib-tk/tkSimpleDialog.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-08-14 14:17:28 (GMT)
committerGuido van Rossum <guido@python.org>1997-08-14 14:17:28 (GMT)
commit1530c879850d48c4f296d248e171ecf7c5d645f3 (patch)
tree9c1a60db8527cfc7b437c8e5882c7b4fdbf781cd /Lib/lib-tk/tkSimpleDialog.py
parentf53c86c2b65edc65db524d98aa42a06605c59de8 (diff)
downloadcpython-1530c879850d48c4f296d248e171ecf7c5d645f3.zip
cpython-1530c879850d48c4f296d248e171ecf7c5d645f3.tar.gz
cpython-1530c879850d48c4f296d248e171ecf7c5d645f3.tar.bz2
Fred Lundh's latest versions.
Diffstat (limited to 'Lib/lib-tk/tkSimpleDialog.py')
-rw-r--r--Lib/lib-tk/tkSimpleDialog.py26
1 files changed, 17 insertions, 9 deletions
diff --git a/Lib/lib-tk/tkSimpleDialog.py b/Lib/lib-tk/tkSimpleDialog.py
index 68f414a..c297922 100644
--- a/Lib/lib-tk/tkSimpleDialog.py
+++ b/Lib/lib-tk/tkSimpleDialog.py
@@ -115,6 +115,7 @@ import string
class _QueryDialog(Dialog):
def __init__(self, title, prompt,
+ initialvalue=None,
minvalue = None, maxvalue = None,
parent = None):
@@ -127,16 +128,22 @@ class _QueryDialog(Dialog):
self.minvalue = minvalue
self.maxvalue = maxvalue
+ self.initialvalue = initialvalue
+
Dialog.__init__(self, parent, title)
def body(self, master):
- w = Label(master, text=self.prompt)
+ w = Label(master, text=self.prompt, justify=LEFT)
w.grid(row=0, padx=5, sticky=W)
self.entry = Entry(master, name="entry")
self.entry.grid(row=1, padx=5, sticky=W+E)
+ if self.initialvalue:
+ self.entry.insert(0, self.initialvalue)
+ self.entry.select_range(0, END)
+
return self.entry
def validate(self):
@@ -147,7 +154,7 @@ class _QueryDialog(Dialog):
result = self.getresult()
except ValueError:
tkMessageBox.showwarning(
- "Bad value",
+ "Illegal value",
self.errormessage + "\nPlease try again",
parent = self
)
@@ -157,16 +164,16 @@ class _QueryDialog(Dialog):
tkMessageBox.showwarning(
"Too small",
"The allowed minimum value is %s. "
- "Please try again" % self.minvalue,
+ "Please try again." % self.minvalue,
parent = self
)
return 0
if self.maxvalue is not None and result > self.maxvalue:
tkMessageBox.showwarning(
- "Bad value",
+ "Too large",
"The allowed maximum value is %s. "
- "Please try again" % self.maxvalue,
+ "Please try again." % self.maxvalue,
parent = self
)
return 0
@@ -177,7 +184,7 @@ class _QueryDialog(Dialog):
class _QueryInteger(_QueryDialog):
- errormessage = "Invalid integer"
+ errormessage = "Not an integer."
def getresult(self):
return string.atoi(self.entry.get())
@@ -186,7 +193,7 @@ def askinteger(title, prompt, **kw):
return d.result
class _QueryFloat(_QueryDialog):
- errormessage = "Invalid floating point value"
+ errormessage = "Not a floating point value."
def getresult(self):
return string.atof(self.entry.get())
@@ -207,6 +214,7 @@ if __name__ == "__main__":
root = Tk()
root.update()
- print askinteger("Spam", "Egg count")
- print askfloat("Spam", "Egg weight")
+ print askinteger("Spam", "Egg count", initialvalue=12*12)
+ print askfloat("Spam", "Egg weight\n(in tons)", minvalue=1, maxvalue=100)
print askstring("Spam", "Egg label")
+