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.

Title: Localize tkinter.simpledialog.Default buttons as with file dialogs.
Type: enhancement Stage: patch review
Components: Tkinter Versions: Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: jcrmatos, python-dev, sampo.hippelainen, serhiy.storchaka, terry.reedy
Priority: normal Keywords: patch

Created on 2017-09-27 17:14 by jcrmatos, last changed 2022-04-11 14:58 by admin.

Pull Requests
URL Status Linked Edit
PR 31682 open python-dev, 2022-03-04 14:29
Messages (7)
msg303162 - (view) Author: (jcrmatos) * Date: 2017-09-27 17:14

tkinter.simpledialog default buttons (not buttonbox) are not localized, unlike all messagebox.

Best regards,

msg303169 - (view) Author: (jcrmatos) * Date: 2017-09-27 19:09

Here is some example code:

from tkinter import Label, Tk
from tkinter.simpledialog import Dialog

class CalendarDialog(Dialog):
    def __init__(self, parent, title='', year=0, month=0):
        self.year = year  # type: int
        self.month = month  # type: int

        Dialog.__init__(self, parent, 'Select a date')

    def body(self, parent):
        Label(parent, text='A label').pack()

master = Tk()
result = CalendarDialog(master, year=2017, month=9).result

Best regards,

msg303173 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-09-27 19:35
What do you expect and what do you get?
msg303182 - (view) Author: (jcrmatos) * Date: 2017-09-27 21:29

I would expect the same behaviour as askopenfilename from tkinter.filedialog where the buttons are localized (in my case in Portuguese).

What I get is the buttons (in tkinter.simpledialog) are always in English.

Best regards,

msg303383 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-09-30 01:04
Tkinter wraps the tcl/tk gui framework.  The file dialogs and messageboxes are provided by tk.  When possible, the file dialogs utilize the native OS file dialogs.  The localization is done the by the OS. If the messageboxes are localized, then I presume the same is true of them also.

tkinter.simpledialog is a tkinter add-on module written in Python, using tk widgets.  SimpleDialog does not have default buttons; they must be supplied in the initialization call.  Dialog does provide default *example* buttons.  The docstring says "override if you do not want the standard buttons".  

Tk does not provide localized [Ok] and [Cancel] buttons.  AFAIK, Python does not provide access to the OS local translations. You will have to provide localization yourself.

A reasonable enhancement request might be to add "ok='OK', cancel='Cancel'" to the signature of Dialog.__init__ so that a user could pass in local translations. These would then be passed on to buttonbox, to be used instead of the current hard-coded strings.
msg303384 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-09-30 01:07
I would make such new paremeters keyword-only.
msg414529 - (view) Author: Sampo Hippeläinen (sampo.hippelainen) * Date: 2022-03-04 14:30
>Tk does not provide localized [Ok] and [Cancel] buttons.

This is not true. You can call ::msgcat::mc to localize core strings such as "OK" and "Cancel".

The full becomes"namespace", "eval", "::tk", "::msgcat::mc", s)

to translate a string s, such as "OK".

I have made a custom modified version of that makes use of this and indeed localizes the OK/Cancel buttons as they would be localized for tk messageboxes (which use Tcl/Tk Core localization). I submitted this now as a GitHub PR.
Date User Action Args
2022-04-11 14:58:52adminsetgithub: 75794
2022-03-04 14:30:18sampo.hippelainensetnosy: + sampo.hippelainen
messages: + msg414529
2022-03-04 14:29:27python-devsetkeywords: + patch
nosy: + python-dev

pull_requests: + pull_request29801
stage: patch review
2017-09-30 01:07:17terry.reedysetmessages: + msg303384
2017-09-30 01:04:35terry.reedysetnosy: + terry.reedy
title: tkinter.simpledialog default buttons (not buttonbox) are not localized, unlike all messagebox -> Localize tkinter.simpledialog.Default buttons as with file dialogs.
messages: + msg303383

versions: + Python 3.7, - Python 3.5
type: behavior -> enhancement
2017-09-27 21:29:04jcrmatossetmessages: + msg303182
2017-09-27 19:35:09serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg303173
2017-09-27 19:09:21jcrmatossetmessages: + msg303169
2017-09-27 17:14:51jcrmatoscreate