【问题标题】:Perl Tkx examples or tutorialsPerl Tkx 示例或教程
【发布时间】:2013-05-31 08:34:21
【问题描述】:

我一直在尝试使用 Tkx 创建 Perl GUI,但遇到了一些问题。

我一直在看这些网站:

http://rainbow.ldeo.columbia.edu/documentation/tkperl/

http://docs.activestate.com/activetcl/8.5/tcl/tk_contents.htm

http://www.tkdocs.com/tutorial/onepage.html

但问题是这些示例似乎对我不起作用。

我想尽可能多地使用面向对象的方法,但不使用 moose(目前),这样我就可以了解对象在 Perl 中是如何工作的。

编辑:link 一个好的 oo 教程

所以我已经可以创建一个窗口了:

sub main
{
    my $mainWindow = Tkx::widget->new(".");
    $mainWindow->g_wm_title("FixViewer");
    $mainWindow->g_wm_minsize(400,500);

    Tkx::MainLoop();
}

如何创建框架并在其上放置 Gridlayout?

谁能告诉我怎么做,或者给我一个好的教程。

谢谢

更新:

use strict;
use warnings;
use Tkx;

sub main
{
    my $mainWindow = Tkx::widget->new(".");
    $mainWindow->g_wm_title("FixViewer");
    $mainWindow->g_wm_minsize(100,100);

    my $contentFrame = $mainWindow->new_ttk__frame(-padding => "3 3 12 12");
    $contentFrame->g_grid(-column => 0, -row => 0, -sticky => "nwes");
    $mainWindow->g_grid_columnconfigure(0, -weight => 1);
    $mainWindow->g_grid_rowconfigure(0, -weight => 1);

    my $input;
    my $output;

    #create a textbox where user can enter input
    my $inputbox = $contentFrame->new_ttk__entry(-width => 7, -textvariable => \$input);
    $inputbox->g_grid(-column => 1, -row => 1, -sticky => "we");

    #create a lable which shows whatever is input in the input box
    my $inputlabel = $contentFrame->new_ttk__label(-textvariable => \$output);
    $inputlabel->g_grid(-column => 1, -row => 2, -sticky => "we");

    #create a button and bind a sub to it
    my $button = $contentFrame->new_ttk__button(-text=> "Click me",-command=> sub {dostuff(\$output,\$input);} );
    $button->g_grid(-column => 1, -row => 3, -sticky => "w");

    #bind return key to method, so method will get called when key is hit
    $mainWindow->g_bind("<Return>",sub {dostuff(\$output,\$input);});

    Tkx::MainLoop;
}

sub dostuff
{
    my $output = shift;
    my $input = shift;
    $$output = $$input;
}

#############
# Call main #
&main();
#############

我设法弄明白了一些东西。仍然非常欢迎提供更多示例或教程链接

【问题讨论】:

标签: perl user-interface tkx


【解决方案1】:
 my $contentFrame = $mainWindow->new_ttk__frame(-padding => "3 3 12 12");
    $contentFrame->g_grid(-column => 0, -row => 0, -sticky => "nwes");
    $mainWindow->g_grid_columnconfigure(0, -weight => 1);
    $mainWindow->g_grid_rowconfigure(0, -weight => 1);

【讨论】:

    猜你喜欢
    • 2020-05-20
    • 1970-01-01
    • 1970-01-01
    • 2012-10-20
    • 2011-07-04
    • 2012-02-01
    • 2017-01-07
    • 2020-07-16
    • 1970-01-01
    相关资源
    最近更新 更多