如何使用 Python tkinter 设置消息框的字体? [英] How to set font of a messagebox with Python tkinter?

查看:77
本文介绍了如何使用 Python tkinter 设置消息框的字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 tkinter 中提供的简单消息框,我想知道是否有任何方法可以更改字体.

I'm using the simple message-boxes provided in tkinter and I'm wondering if there's any way to change the font.

这是我想要的总体思路,但是 font= 选项不起作用.

This is the general idea of what I want, but the font= option doesn't work.

from tkinter import Tk
import tkinter.messagebox as tkmsg

_root = Tk()
_root.withdraw()
tkmsg.showinfo(
    "Info",
    "Some monospaced text",
    font=("Monospace", 15)
)
_root.destroy()

有什么办法可以改变字体还是我必须使用自定义对话框?

Is there any way to change the font or do I have to use a custom dialog?

推荐答案

你不能.使用顶层widgted (tkinter.Toplevel()) 和标签编写您自己的消息框!

you can't. write your own messagebox using the toplevel widgted (tkinter.Toplevel()) and label!

类似的东西(来自 http://effbot.org/tkinterbook/label.htm)

from Tkinter import *

master = Tk()

w = Label(master, text="Hello, world!")
w.pack()

mainloop()

希望能帮到你!

这篇关于如何使用 Python tkinter 设置消息框的字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆