【问题标题】:perl tk drag & drop folder from windows explorerperl tk 从 Windows 资源管理器拖放文件夹
【发布时间】:2014-01-07 05:11:03
【问题描述】:

全部,

我有一个我正在开发的 win32 perl TK 应用程序,为了让用户更简单,我想将文件夹的 N 拖放功能从 Windows 资源管理器/桌面拖放到我的应用程序中的小部件(例如文本框等)上.

原因是消除手动目录/文件选择对话框等。

一些示例代码将不胜感激。提前致谢。

杰里米。

【问题讨论】:

  • 在 Perl/Tk 源代码分发中,DragDrop 目录中有一些示例脚本。你能检查一下这些(例如site_test)是否适合你吗?

标签: perl winapi drag-and-drop tk directory


【解决方案1】:

有一个模块 Tk::DropSite 应该适合你。

可以在此处找到示例代码:http://www.nntp.perl.org/group/perl.tcltk/2010/02/msg375.html

这是一个工作示例代码:

#!perl

use strict;
use Tk;
use Tk::DropSite;
use Tk::Pane;

my $textVariable = "drag here";

my $mw = MainWindow->new;

my $frame = $mw->Frame(
)->pack(-side => 'top', -expand => 1, -fill => 'x');

$frame->Label(
    -text => "My Label",
    -anchor => 'w',
    -width => 10,
)->pack(-ipady => 1, -side => 'left');

my $entry = $frame->Entry(
    -textvariable => \$textVariable,
    -width => 40,
)->pack(-side => 'left');

$frame->DropSite(
    -dropcommand => [\&AcceptDrop, $frame],
    -droptypes => ('Win32'),
);

$mw->MainLoop;


sub AcceptDrop {
    my ($widget, $selection) = @_;
    my $filename;

    $filename = $widget->SelectionGet(
        -selection => $selection, 
        'STRING'
    );
    $textVariable = $filename;
} # /AcceptDrop

如果你懂德语,请看这里:http://www.perltk.de/tk_widgets/howto_perl_tk_tkx_comparison.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-26
    • 2012-05-02
    相关资源
    最近更新 更多