【问题标题】:Tcl Tk to show images in ScilabTcl Tk 在 Scilab 中显示图像
【发布时间】:2016-06-17 10:20:56
【问题描述】:

我想使用 Tcl/Tk 制作的 GUI 在 Scilab 中显示图像和视频。

Scilab 支持 Tcl/Tk :- https://help.scilab.org/docs/6.0.0/en_US/section_a10b99d9dda4c3d65d29c2a48e58fd88.html

我制作了一个 tcl 脚本,当从终端运行时会显示图像。

image create photo img -file <filepath>
pack [label .mylabel]
.mylabel configure -image img

但是,当我在 scilab 中编写以下 .sci 文件时,它执行成功,但没有显示图像窗口。

function sampletry()
    TCL_EvalFile(<path_to_tcl_file>);
endfunction

我确实知道代码执行成功了,因为当我在 scilab 中再次执行相同的函数时,我收到一条错误消息,指出标签 .mylabel 已存在于父窗口中。

有什么方法可以在 Scilab 中使用此方法或 Scilab 中的任何其他方法显示图像/视频?我正在使用 OpenCV 读取图像并通过列表中的 Scilab Api 将其返回给 Scilab。

【问题讨论】:

    标签: opencv image-processing tcl tk scilab


    【解决方案1】:

    问题是您没有从 Scilab 代码中为事件循环提供服务,否则来自操作系统的与实际将窗口放在屏幕上有关的大量消息永远无法通过和处理。假设您希望您的代码停止并等待查看完成,您只需将 Tcl/Tk 代码更改为:

    image create photo img -file <filepath>
    if {![winfo exists .mylabel]} {
        pack [label .mylabel]
    }
    .mylabel configure -image img
    wm deiconify .
    # Wait for the user to ask for the window to be closed
    wm protocol . WM_DELETE_WINDOW {set done 1}
    vwait done
    # Process the close immediately
    wm withdraw .
    update
    

    done 变量没有什么特别之处。我们只是在等待它在回调中设置。我添加了一些额外的代码以允许您调用它两次(即有条件地创建小部件,确保显示 .,然后在最后隐藏它)。

    如果您不想将所有内容都保留在同一进程中,最简单的方法是将您的原始脚本作为一个单独的程序运行,有效地执行以下操作:

    wish <path_to_tcl_file>
    

    我不知道 Scilab 最简单的方法是什么。

    【讨论】:

    • 如果我不想等到观看完成怎么办?我希望控件在窗口显示后立即返回到 Scilab,而无需等待它关闭。
    • 请帮我解决这个问题。
    猜你喜欢
    • 2021-08-01
    • 2017-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多