This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: tkinter SimpleDialog initialvalue
Type: behavior Stage: resolved
Components: Tkinter Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: asvetlov Nosy List: asvetlov, busfault, python-dev
Priority: normal Keywords: patch

Created on 2011-06-08 21:28 by busfault, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
tkSimpleDialog.py busfault, 2011-06-08 21:28 tkSimpleDialog
issue12288.diff asvetlov, 2012-07-29 12:27 review
Messages (4)
msg137925 - (view) Author: Tom Middleton (busfault) Date: 2011-06-08 21:28
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.
msg166751 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2012-07-29 12:27
Add patch for py3k
msg166912 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-07-30 17:05
New changeset fd5166fdb978 by Andrew Svetlov in branch '3.2':
Issue #12288: Consider '0' and '0.0' as valid initialvalue for tkinter SimpleDialog.
http://hg.python.org/cpython/rev/fd5166fdb978

New changeset 2f3ccf4ec193 by Andrew Svetlov in branch 'default':
Issue #12288: Consider '0' and '0.0' as valid initialvalue for tkinter SimpleDialog.
http://hg.python.org/cpython/rev/2f3ccf4ec193

New changeset f98e2944cb40 by Andrew Svetlov in branch '2.7':
Issue #12288: Consider '0' and '0.0' as valid initialvalue for tkinter SimpleDialog.
http://hg.python.org/cpython/rev/f98e2944cb40
msg166914 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2012-07-30 17:12
Fixed. Thank you, Tom.
History
Date User Action Args
2022-04-11 14:57:18adminsetgithub: 56497
2012-07-30 17:12:45asvetlovsetstatus: open -> closed
resolution: fixed
messages: + msg166914

stage: resolved
2012-07-30 17:05:20python-devsetnosy: + python-dev
messages: + msg166912
2012-07-29 12:28:29asvetlovsettitle: Python 2.7.1 tkSimpleDialog initialvalue -> tkinter SimpleDialog initialvalue
2012-07-29 12:27:53asvetlovsetfiles: + issue12288.diff

assignee: asvetlov
versions: + Python 3.2, Python 3.3
keywords: + patch
nosy: + asvetlov

messages: + msg166751
2011-06-08 21:28:03busfaultcreate