FILE SELECTION DIALOG PROBLEM

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default FILE SELECTION DIALOG PROBLEM

    I am using the following code to create file selection dialogs..But
    apparently the Browse buttons do not seem to work.. i got this from
    examples provided by typing widget. I changed a little to remove the
    radio buttons and stuff, but i am not able to browse and select the
    files. I will be glad if anyone can point the error and throw some
    light on this.
    Thanks very much.

    use Tk;
    $mw = MainWindow->new();

    foreach my $i (qw(one two three four)) {
    my $f = $mw->Frame;
    my $lab = $f->Label(-text => "Select $i file to Open: ",
    -anchor => 'e');
    my $ent = $f->Entry(-width => 20);
    my $but = $f->Button(-text => "Browse ...",
    -command => sub { fileDialog($mw, $ent, $i)});
    $lab->pack(-side => 'left');
    $ent->pack(-side => 'left',-expand => 'yes', -fill => 'x');
    $but->pack(-side => 'left');
    $f->pack(-fill => 'x', -padx => '1c', -pady => 3);
    }


    sub filebox {
    my $demo = shift;


    (
    -name => $demo,
    -text => "Enter a file name in the entry box or click on
    the \"Browse\" buttons to select a file name

    using the file selection dialog.",
    -iconname => 'filebox',
    );
    }

    sub fileDialog {
    my $w = shift;
    my $ent = shift;
    my $operation = shift;
    my $types;
    my $file;
    @types =
    (["Text files", '*.txt'],
    ["All files", '*']
    );
    if ($operation eq 'open') {
    $file = $w->getOpenFile(-filetypes => \@types);
    }

    }
    Go Perl Guest

  2. Similar Questions and Discussions

    1. Download a file without a dialog box
      Hello: I'm tryng to download an image and showing it in an image control of a flex 2 or 3 application. In the FileIO example I get this fr = new...
    2. file open dialog
      i know this is the 3d forum but i swear i have seen the answer to my question on this list before. is there a shockwave-safe file xtra or...
    3. File Dialog Xtras?
      Hey all, doest anyone know of a Cross Platform (Windows/OSX) Xtra that allows you to open a file dialog where you can select multiple files? The...
    4. help with file dialog
      "Go Perl" <puissant00@yahoo.com> wrote in message news:d3825316.0307290829.35a72bc3@posting.google.com... This is the subroutine that gets called...
    5. File Dialog Box
      Does anyone know how do to get a file dialog box to work for Access 2000? I want to create a form that allows me to search for the file, put the...
  3. #2

    Default Re: FILE SELECTION DIALOG PROBLEM

    Go Perl wrote:
    > I am using the following code to create file selection dialogs..But
    > apparently the Browse buttons do not seem to work.. i got this from
    > examples provided by typing widget. I changed a little to remove the
    > radio buttons and stuff, but i am not able to browse and select the
    > files. I will be glad if anyone can point the error and throw some
    > light on this.
    ....
    >
    > use Tk;
    > $mw = MainWindow->new();
    >
    > foreach my $i (qw(one two three four)) {
    > my $f = $mw->Frame;
    > my $lab = $f->Label(-text => "Select $i file to Open: ",
    > -anchor => 'e');
    > my $ent = $f->Entry(-width => 20);
    > my $but = $f->Button(-text => "Browse ...",
    > -command => sub { fileDialog($mw, $ent, $i)});
    > $lab->pack(-side => 'left');
    > $ent->pack(-side => 'left',-expand => 'yes', -fill => 'x');
    > $but->pack(-side => 'left');
    > $f->pack(-fill => 'x', -padx => '1c', -pady => 3);
    > }

    MainLoop; #is needed here

    >
    >
    > sub filebox {
    > my $demo = shift;
    >
    >
    > (
    > -name => $demo,
    > -text => "Enter a file name in the entry box or click on
    > the \"Browse\" buttons to select a file name
    >
    > using the file selection dialog.",
    > -iconname => 'filebox',
    > );
    > }
    >
    > sub fileDialog {
    > my $w = shift;
    > my $ent = shift;
    > my $operation = shift;
    > my $types;
    > my $file;
    > @types =
    > (["Text files", '*.txt'],
    > ["All files", '*']
    > );
    > if ($operation eq 'open') {
    > $file = $w->getOpenFile(-filetypes => \@types);
    > }
    >
    > }
    >
    Your "browse" buttons work fine. The sub you are calling with the
    -command of each Button is not given a third argument of 'open',
    however, so it appears as if the Button does nothing. If you change it
    so the the third argument is 'open' instead of $i, then the file dialog
    does appear. But then, you don't do anything with $file once you have
    it, so your program needs lots more work.

    And BTW, your example is missing a MainLoop; statement in the main program.

    --
    Bob Walton

    Bob Walton Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139