LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Easy perltk question. (https://www.linuxquestions.org/questions/programming-9/easy-perltk-question-519198/)

cyb0rg777 01-14-2007 10:54 AM

Easy perltk question.
 
How do I change the window font?
It's like 5 times bigger than everything on my desktop.
Can't find anything describing how to do this.
A good source of examples or documentation would be very helpful.
Thanks.

cyb0rg777 01-15-2007 12:11 PM

I found it.
I found some info in the man page.Here is how you do it.

Code:

#!/usr/bin/perl -w
use Tk;
my $mw=new MainWindow;
my $label = $mw->Label(-font=>['helvetica',10],-text => "Some text");
$label->pack;
my $messages=$mw->messageBox(-message=>"font",-font=>['times',8]);
MainLoop;

I only found 3 fonts times,helvetica and courier.I'm just learning Tk and perl and so far it's great. :)

matthewg42 01-15-2007 12:50 PM

You can also save fonts in the MainWindow object, and refer to them by name. This makes it a little easier to change the appearance of your app at a later date (single point of modification):
Code:

#!/usr/bin/perl -w

use Tk;

my $mw = new MainWindow;
$mw->fontCreate(qw/myfont1 -family roman -size 16/);
$mw->fontCreate(qw/myfont2 -family times -size 20/);

my $label = $mw -> Label(-text=>"Hello World", -font => "myfont1") -> pack();
my $button = $mw -> Button(-text => "Quit", -font => "myfont2", -command => sub { exit });
$button->pack();

MainLoop;


matthewg42 01-15-2007 12:51 PM

Tk is quite nice for quick ugly GUI apps. Using TCL instead of Perl is also worth a look - TCL crops up in all sorts of places so it's useful to know, and it's very easy to learn.


All times are GMT -5. The time now is 06:22 AM.