in reply to Re^2: Can't specify font in messageBox
in thread Can't specify font in 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

Replies are listed 'Best First'.
Re^4: Can't specify font in messageBox
by Sandy (Curate) on Apr 26, 2009 at 22:40 UTC
    Theo

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

    The widget demo runs a program msgBox.pl 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 WidgetDemo.pm (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 WidgetDemo.pm 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,

    Sandy

      Thank you very much for doing all this research

      I still don't entirely "get it", but I'll poke around in the files you mentioned until I understand.

      I guess my only solution is to create my own window with a label and buttons that do what I want. It's a lot more work, but it will get the job done.

      Thanks again