Control Font in tkMessageBox

耗尽温柔 提交于 2019-12-19 06:38:10

问题


I would to like to control the font of the text on a tkMessageBox but I can't see any reference of such a stuff. Is it only implemented in Tkinter?

Thanks,


回答1:


You can configure the font for just dialog boxes by doing the following:

from Tkinter import *
import tkMessageBox
r = Tk()
r.option_add('*Dialog.msg.font', 'Helvetica 12')
tkMessageBox.showinfo(message='Hello')

(Only the option_add invocation is modified from the accepted answer.)




回答2:


The following works here. You will need to change the second argument of option to the font type and font size you want.

 from Tkinter import *
 import tkMessageBox
 r = Tk()
 r.option_add('*font', 'Helvetica -12')
 tkMessageBox.showinfo(message='Hello')

You may have to call r.option_clear() to clear it afterwards.

See here for more information about setting the font of other Tkinter widgets.

This doesn't work with tkMessageBox because tkCommonDialog doesn't take the font option.



来源:https://stackoverflow.com/questions/9347645/control-font-in-tkmessagebox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!