首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么`print`在这个wxPerl程序中不能工作?

为什么`print`在这个wxPerl程序中不能工作?
EN

Stack Overflow用户
提问于 2010-07-24 16:31:33
回答 2查看 216关注 0票数 1

在我的框架构造函数中,我有一个函数可以很容易地为我制作一个菜单栏。

代码语言:javascript
复制
package Routines;

#This function will set up a menu
#REQUIRED: entries
#RETURNS:  id, menu
sub SetupMenu {
    $menuItemCount = 0;                     #Element number under the same menu
    $subMenuCount  = 0;                     #Number of menus
    $mbar          = Wx::MenuBar->new();    #Menu bar constructor
    for ($totalCount = 0; $totalCount < scalar($_[1]); $totalCount++) {    #Loop for each entry
        if ($menuItemCount == 0) {                                         #If this is the first entry in the menu
            $menuList[$subMenuCount] = Wx::Menu->new($_[$totalCount]);     #Construct a menu and make this the title
        } elsif ($_[$totalCount] == "---") {                               #If the entry is ---
                                                                           #Treat it as a separator, skip ID
        } elsif ($_[$totalCount] == "***") {                               #If the entry is ***
            $mbar->Append($menuList[$subMenuCount]);                       #Add the menu to the bar
            $menuItemCount = 0;                                            #Reset the number of elements
            $subMenuCount++;                                               #Increment the number of menus
        } else {                                                           #On normal operation
            $menuList[$subMenuCount]->Append($id[$totalCount], $_[$totalCount]);    #Add the element to the menu and assign it an ID
        }
    }
    #print $mbar;
    return (@id, $mbar);
}

#This package puts crap in the main window
package mehFrame;
use base qw(Wx::Frame);

sub new {
    #Preparation
    $class = shift;
    $self  = $class->SUPER::new(@_);

    #Place the panel
    $pan = Wx::Panel->new($self, -1);

    #Set up menus
    (@mehId, $mehBar) = Routines::SetupMenu("File", "Open ROM", "Save ROM", "Save ROM As", "---", "Close ROM", "Exit");

    #Return
    return $self;
}
[...]

不幸的是,它不起作用。在SetupMenu()函数中放入print之后,它没有打印出来。另一方面,当我将其设置为warn时,它会发出警告。

更糟糕的是,即使我在new()函数中放入一个print,它仍然不能打印。怎么一回事?

EN

回答 2

Stack Overflow用户

发布于 2010-07-24 21:25:43

您的描述听起来像是打印到标准错误代码,因为这就是warn要做的事情,而打印到标准错误代码则不行。

试着用print STDERR $mbar代替--我相当确定它会工作。

更新:根据daotoad的优秀建议,这也可以归因于缺乏刷新-如果是这样,那么在STDOUT上设置autoflush就可以解决这个问题。它是一个还是另一个,取决于操作员尝试什么。我将它添加到我的答案中,因为daotoad只发布了一条评论,还没有添加他自己的单独答案-一旦他这样做了,我将删除。

票数 1
EN

Stack Overflow用户

发布于 2010-12-22 09:12:17

打印在Wx下工作,有时在没有添加"\n“的情况下异步打印

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3324404

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档