#
# FIXME: as of Tk 8.0a2, the Unix colour picker is really ugly, and
-# doesn't seem to work properly on a true colour display. maybe we
+# doesn't seem to work properly on true colour displays. maybe we
# should use the instant python version instead?
from tkCommonDialog import Dialog
if __name__ == "__main__":
print "color", askcolor()
+
self._fixoptions()
- # we need a stub widget to properly process the options
+ # we need a dummy widget to properly process the options
# (at least as long as we use Tkinter 1.63)
w = Frame(self.master)
pass
return s
+
class _QueryDialog(Dialog):
def __init__(self, title, prompt,
+ initialvalue=None,
minvalue = None, maxvalue = None,
parent = None):
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):
result = self.getresult()
except ValueError:
tkMessageBox.showwarning(
- "Bad value",
+ "Illegal value",
self.errormessage + "\nPlease try again",
parent = self
)
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
class _QueryInteger(_QueryDialog):
- errormessage = "Invalid integer"
+ errormessage = "Not an integer."
def getresult(self):
return string.atoi(self.entry.get())
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())
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")
+
#
# FIXME: as of Tk 8.0a2, the Unix colour picker is really ugly, and
-# doesn't seem to work properly on a true colour display. maybe we
+# doesn't seem to work properly on true colour displays. maybe we
# should use the instant python version instead?
from tkCommonDialog import Dialog
if __name__ == "__main__":
print "color", askcolor()
+
self._fixoptions()
- # we need a stub widget to properly process the options
+ # we need a dummy widget to properly process the options
# (at least as long as we use Tkinter 1.63)
w = Frame(self.master)
pass
return s
+
class _QueryDialog(Dialog):
def __init__(self, title, prompt,
+ initialvalue=None,
minvalue = None, maxvalue = None,
parent = None):
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):
result = self.getresult()
except ValueError:
tkMessageBox.showwarning(
- "Bad value",
+ "Illegal value",
self.errormessage + "\nPlease try again",
parent = self
)
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
class _QueryInteger(_QueryDialog):
- errormessage = "Invalid integer"
+ errormessage = "Not an integer."
def getresult(self):
return string.atoi(self.entry.get())
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())
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")
+