1

I would like This is a help message: in the following string to be displayed in bold.

help_message = """This is a help message:
 Demo!"""

tk.messagebox.showinfo('Help', help_message)

Can this be done with """{}content""".format('some_style_string')?


I have seen other examples use code like the following:

class color:
    PURPLE = '\033[95m'
    CYAN = '\033[96m'
    DARKCYAN = '\033[36m'
    BLUE = '\033[94m'
    GREEN = '\033[92m'
    YELLOW = '\033[93m'
    RED = '\033[91m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'
    END = '\033[0m'

But all the examples seem to involve the use of print.

1 Answer 1

3

Can this be done with """{}content""".format('some_style_string')

No, it cannot. tk.messagebox cannot show styled text.

I have seen other examples use code like the following...

No, that won't work either. Those are escape codes that are designed to be interpreted by an ansi terminal (or by the curses package).

If you want styled text then you will have to create your own dialog with Toplevel and some text, label, or canvas widgets.

Sign up to request clarification or add additional context in comments.

2 Comments

other examples show 'master.option_add('*Dialog.msg.font', 'Helvetica 12')', is syntax this possible? and I haven't really mastered class design with python/tkinter as yet, do you have a good generic messagebox (toplevel) example?
@10SecTom: examples are just a google search away. Here's one: effbot.org/tkinterbook/tkinter-dialog-windows.htm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.