in reply to Tk BrowseEntry with only the arrow button visible?

Is there a simpler solution?

DIY :)

Is there a different drop-down list widget that is displayed as only a button?

Don't know , maybe, would investigate tk j ... Tk::JFileDialog Tk::JComboBox Tk::JBrowseEntry ...

Is there a simpler solution?

Looking at a widgetdump, you can do  $jb1 ->Subwidget('entry')->packForget ; that works to hide it

this messes up the width, so you'd have to bind the button to pack before invoking original button handler

{ my $parent = $jb1 ; my $arrow = $jb1 ->Subwidget('arrow'); my $callback = $arrow->bind('<Button-1>'); $jb1 ->Subwidget('entry')->packForget; $arrow->bind('<Button-1>', [ sub { my( $button, $jbl, $callbackarray ) = @_; warn "fucking @_\n"; warn "button($button) jbl($jbl) callback($callback)\n"; $jbl->Subwidget('entry')->pack(-side => "right", -fill => +'x', -padx => 0, -pady => 0, -expand => 1); my( $cb, @args ) = @$callbackarray; $cb->(@args); }, $parent, $callback, ] ); }

This is only half ... if anything it tells you what to edit in Tk::JBrowseEntry :D in Tk::BrowseEntry::SetBindings ...

update:

#!/usr/bin/perl -- use strict; use warnings; use Tk; use Tk::BrowseEntry; Main( @ARGV ); exit( 0 ); sub Tk::BrowseEntry::Popdown { my ($w) = @_; if ( $w->{'_BE_savefocus'} && Tk::Exists( $w->{'_BE_savefocus'} ) +) { $w->{'_BE_savefocus'}->focus; delete $w->{'_BE_savefocus'}; } if ( $w->{'_BE_popped'} ) { my $c = $w->Subwidget('choices'); $c->withdraw; $w->grabRelease; if ( ref $w->{'_BE_grabinfo'} eq 'CODE' ) { $w->{'_BE_grabinfo'}->(); delete $w->{'_BE_grabinfo'}; } $w->{'_BE_popped'} = 0; $w->Subwidget('entry')->packForget; } } sub Tk::BrowseEntry::BtnDown { my ($w) = @_; return if $w->cget( '-state' ) eq 'disabled'; if ($w->{'_BE_popped'}) { $w->Popdown; $w->{'_BE_buttonHack'} = 0; } else { $w->Subwidget('entry')->pack(-side => 'right', -fill => 'x', - +expand => 1); $w->update; $w->PopupChoices; $w->{'_BE_buttonHack'} = 1; } } sub Main { my $mw = tkinit(); my $var = 'lelabel'; my $b = $mw->BrowseEntry(-label => "Label", -variable => \$var); $b->insert("end", "opt1"); $b->insert("end", "opt2"); $b->insert("end", "opt3"); $b->Subwidget('entry')->packForget; $b->pack; MainLoop; }
  • Comment on Re: Tk BrowseEntry with only the arrow button visible? ( override Tk::BrowseEntry::SetBindings / sub Tk::JBrowseEntry::Popdown)
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Tk BrowseEntry with only the arrow button visible? ( override Tk::BrowseEntry::SetBindings / sub Tk::JBrowseEntry::Popdown)
by elef (Friar) on Dec 23, 2013 at 09:06 UTC
    Thanks.
    I tried your code posted as an update, and it mostly does what I want, but the entry field still shows up when I click the button. I would want it to stay hidden all the time. I tried removing the whole BtnDown sub, removing just the $w->Subwidget('entry')->pack line, and adding a packForget right after it. The result is the same in all three cases: the entry field is hidden, but the listbox that pops up starts at the left edge of the screen and stretches all the way to the button. I tried looking in the BrowseEntry.pm to see what sets the width but most of it goes way over my head. Adding -listwidth   => 30 brings me back to where I started: the listbox is the correct width but it's at the edge of the screen.

      :) ... blah blah ... :)

      so DIY , a button, onclick popup a toplevel, popoff when toplevel loses focus (or mainwindow gains focus)

      its easier to popup a genuine Tk::Menu ...