New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Localize tkinter.simpledialog.Default buttons as with file dialogs. #75794
Comments
Hello, tkinter.simpledialog default buttons (not buttonbox) are not localized, unlike all messagebox. Best regards, JM |
Hello, 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
master.mainloop() Best regards, JM |
What do you expect and what do you get? |
Hello, 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, JM |
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. |
I would make such new paremeters keyword-only. |
This is not true. You can call ::msgcat::mc to localize core strings such as "OK" and "Cancel". The full tk.call becomes tk.call("namespace", "eval", "::tk", "::msgcat::mc", s) to translate a string s, such as "OK". I have made a custom modified version of simpledialog.py 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. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: