RMWChaos
RMWChaos

Reputation: 885

wxpython change message dialog font?

Python 2.7.3 x64 wxPython 2.8 x64

I'm having trouble changing the font of the wxpython message dialog box. I'd like to use a fixed-width font (I think wxFAMILY_MODERN is) to control the formatting of the output. Here's the code I'm using to test with ...

def infDialog (self, msg, title):
    """ Display Info Dialog Message """
    font = wx.Font(14, wx.MODERN, wx.NORMAL, wx.NORMAL)
    style = wx.OK | wx.ICON_INFORMATION | wx.STAY_ON_TOP
    dialog = wx.MessageDialog(self, msg, title, style)
    dialog.CenterOnParent()
    dialog.SetFont(font)
    result = dialog.ShowModal()
    if result == wx.ID_OK:
        print dialog.GetFont().GetFaceName()
    dialog.Destroy()
    return
# End infDialog()

But the results when I click OK are always "Arial". Any thoughts? Perhaps I need to make a custom dialog class?

Thanks,

-RMWChaos

Upvotes: 1

Views: 2766

Answers (2)

A Hanson
A Hanson

Reputation: 11

I was looking all over the internet and found that no one actually took the time to answer the question, instead just telling users to create their own dialog class. There is actually an easy way in which you should be able to change the font of your message dialog. Grabbing the dialog's textCtrl object and then setting the font of that object should do the trick.

Simply replace:

dialog.SetFont(font)

with

txt_ctrl = dialog.text
txt_ctrl.SetFont(font)

Let me know if this works for you.

Upvotes: 1

Mike Driscoll
Mike Driscoll

Reputation: 33071

The wx.MessageDialog is a wrapper around the OS / system message dialog. I suspect each OS only allows so much editing or none at all. So yes, using a custom wx.Dialog or the generic message dialog widget (wx.lib.agw.genericmessagedialog) is the way to go if fonts are important.

Upvotes: 1

Related Questions