Issue 12288: tkinter SimpleDialog initialvalue (original) (raw)

Using Tkinter under Python 2.7.1 (Windows XP FWIF) If using the tkSimpleDialog.askinteger() function with an initialvalue = 0, the 0 is not displayed in the dialog box. The same is true for tkSimpleDialog.askfloat().

The cause of this seems to be the following: in Lib\libi-tk\tkSimpleDialog.py (attached for convenience) under class _QueryDialog(Dialog)

def body(self, master):

    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

The if self.initialvalue will evaluate to a FALSE when the initial value is a 0.

Changing this line to:

if self.initialvalue is not None:

fixed this issue. I am not certain that this is as intended or a bug.