minerz029 minerz029 - 3 months ago 51
Python Question

How to set font of a messagebox with Python tkinter?

I'm using the simple message-boxes provided in

tkinter
and I'm wondering if there's any way to change the 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?

Answer

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

Something like this (from http://effbot.org/tkinterbook/label.htm)

from Tkinter import *

master = Tk()

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

mainloop()

i hope it helps!

Comments