Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Can't specify font in messageBox

by Sandy (Curate)
on Apr 23, 2009 at 21:45 UTC ( #759677=note: print w/replies, xml ) Need Help??

in reply to Can't specify font in messageBox

I tried your code on a Unix machine (Solaris) and it worked just fine.

I tried it on my Windows XP machine, and it did not work fine.

Perhaps it is because Tk calls the native messageBox?? and Windows is more restrictive??

Interesting note: According to the docs, -font is not a valid option for messageBox, so it suprises me that it works on Unix.

Replies are listed 'Best First'.
Re^2: Can't specify font in messageBox
by Theo_124 (Novice) on Apr 23, 2009 at 22:22 UTC

    Thank you for confirming that it's not just me :)

    So the next interesting bit is that the widget demo uses a different font in their messageBoxes demo than I see with my code snippet (above). When I click their "See Code" button and look, they do not set the font at all. All of my experimenting is being done from Windows.

    So perhaps Windows grabs some kind of "default" font based on something... and uses THAT in the messageBox.

    I'll try changing the default font in my program and see if that changes the font in the messageBox...

      I just tried changing the font for my test script using RefontTree to re-set the font on my whole program and it will not change the font in the messageBox.

      This is very strange because the widget demo DOES use a different font in the messageBox that it displays, but I can't figure out how. The widget demo never CHANGES the font that it uses in the messageBox, but it is a larger bolder font than the one that I always get.

      Here is my code that shows the ability to change the font for the whole rest of the program, but the messageBox is always the same

      use strict; use warnings; use Tk; use Tk::FontDialog; my $mw=new MainWindow; $mw->Label(-text => "Test")->pack; $mw->Button(-text => "Another test")->pack; $mw->Button(-text => "Use Tk::FontDialog", -command => sub { my $font = $mw->FontDialog->Show; if (defined $font) { $mw->RefontTree(-font => $font); } })->pack; my $mess .= "\nAre these two customers the same?"; $mw->Button(-text => "Test messageBox", -command => sub { my $res = $mw -> messageBox( -title => "This is a test", -message => $mess, -type => 'yesno'); } )->pack; MainLoop;

      Does anyone have any ideas here? Or what I could try?

      I'd give up, except for the fact that I KNOW it can be done because the widget demo shows it!

      Thank you for any tips or advice you might have for me


        I think I see the misunderstanding with respect to the demo.

        The widget demo runs a program in C:\Perl\lib\Tk\demos\widget_lib. Looking at this code,

        sub msgBox { my($demo) = @_; $TOP = $MW->WidgetDemo( -name => $demo, -text => 'Choose the icon and type option of the m +essage box. '. 'Then press the "Message Box" button to s +ee the message box.', -title => 'messageBox Demo', -iconname => 'messageBox', );
        you can see that it creates a WidgetDemo object, which is the dialog box that has the large font. This object is defined in the program (same directory).
        my %WIDGDEMO; # class hash of active widget demonstrations sub Populate { my($self, $args) = @_; my (%arg_defaults) = ( -name => 'Unknown Demo Name', -font => 'Helvetica 24', ### I changed this! -text => 'Unknown Demo Text', -geometry_manager => 'pack', );
        I fiddled with the font size to prove to myself that this is where it can become larger (or smaller if you wish).

        However... the messageBox that it creates by pressing the button is not affected by the font size defined in the module.

        So, my conclusion is that we cannot adjust the size of the message box font (in windows) using Tk.

        You can modify the font size in the windows 'display properties' that applies to all programs.

        Good luck,


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://759677]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2017-12-18 04:12 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (466 votes). Check out past polls.