简体   繁体   English

Tkinter 自定义按钮上的消息框文本

[英]Tkinter MessageBox text on custom Button

On windows, PredefinedType of Tkinter.Messagebox (for exemple retrycancel) are shown in the Windows default language (retry/cancel if en_US, Recommencer/Annuler if fr_FR, and so on).在 windows 上, Tkinter.MessageboxPredefinedType (例如 retrycancel)显示在 Windows 和默认语言(retry/canceler if fr_FR)中

Is there a way to retrieve those Windows label in order to correctly initialize a custom Button with the respective language translation.有没有办法检索那些 Windows label 以便使用相应的语言翻译正确初始化自定义按钮。

Tkinter.Button(text=????)

It is possible to retrieve the translated strings through the tcl interpreter:可以通过 tcl 解释器检索翻译后的字符串:

import tkinter as tk

def translate(text):
    return root.tk.eval("namespace eval ::tk {::msgcat::mc %s}" % text)


root = tk.Tk()
tk.Button(root, text=translate("retry")).pack()
root.mainloop()

Tcl uses the package msgcat for the internationalization so ::msgcat::mc string returns the translation for string in the current locale. Tcl 使用 package msgcat进行国际化,因此::msgcat::mc string返回当前语言环境中string的翻译。 The namespace eval is needed to access the translations loaded for the tk package.需要namespace eval来访问为tk package 加载的翻译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM