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

Perl/Tk: BrowseEntry Listbox alignment on osx/linux

by mtmcc (Hermit)
on Oct 02, 2013 at 15:28 UTC ( [id://1056628]=perlquestion: print w/replies, xml ) Need Help??

mtmcc has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I was wondering if anyone may be able to help on this minor problem that's starting to bug me.

I'm writing a perl/Tk application that uses a BrowseEntry widget. I've recently noticed that on windows, the listbox drops down perfectly aligned with the entry space every time, but on osx and linux, the listbox always aligns to the left-most edge of the widget. This is fine when the BrowseEntry widget does not have a label, but when it does have a label, the listbox is no longer aligned with the entry space.

As a minimal example, this perl/Tk window has a BrowseEntry widget with a label ('Options:'), and the drop-down list box is misaligned on osx/linux:

#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::BrowseEntry; my $mw = MainWindow -> new; $mw->geometry("350x50"); my $browseEntry = $mw ->BrowseEntry( -label => 'Options:', -state => 'readonly', -autolistwidth => '1', -justify => 'right', -buttontakefocus => 1) -> pack( -ipadx => 35, -side => 'right', -fill => 'x', -anchor => 'e', -expand => 0); $browseEntry -> insert('end', qw(Option_A Option_B Option_C)); MainLoop;

At the moment, the only way I can find to align the listbox and entry space on osx/linux is to use a separate label widget, something like this:

#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::BrowseEntry; my $mw = MainWindow -> new; $mw->geometry("350x50"); my $labelSeparate = $mw ->Label( -text => 'Options:', -width => 15) -> pack( -side => 'left', -fill => 'x', -expand => 1); my $browseEntry = $mw ->BrowseEntry( #-label => 'Options:', -state => 'readonly', -listwidth => '220', -justify => 'right', -buttontakefocus => 1) -> pack( -ipadx => 35, -side => 'left', -fill => 'x', -anchor => 'e', -expand => 1); $browseEntry -> insert('end', qw(Option_A Option_B Option_C)); MainLoop;

But does anybody know if it's possible to adjust the listbox alignment without adding a separate label widget? Windows seems to do this automatically...

Thanks in advance!

Replies are listed 'Best First'.
Re: Perl/Tk: BrowseEntry Listbox alignment on osx/linux
by kcott (Archbishop) on Oct 02, 2013 at 16:49 UTC

    G'day mtmcc,

    Using the option "-style => 'MSWin32'" should do what you want: tested successfully on Mac OS X; I'd expect the same on other *nix OSes. See Tk::BrowseEntry for details.

    -- Ken

      Great fix, thank you kcott!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1056628]
Approved by hdb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-20 00:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found