如何在 tcl tk 中创建超链接?

How to create an hyperlink in tcl tk?

我正在使用 Tcl-Tk 8.6.4,我是初学者,我想在我的文本中创建超链接。 我正在寻找一个可以在参数中包含网站 url 的程序,此 url 将以蓝色显示并在我的文本中加下划线。当然,通过点击 url,它会打开网站。 我找到了以下代码,但我不确定它是否会执行我想要的操作。

proc hyperlink { name args } {
  if { "Underline-Font" ni [ font names ] } {
    font create Underline-Font {*}[ font actual TkDefaultFont ]
    font configure Underline-Font -underline true -size 12
  }
  if { [ dict exists $args -command ] } {
    set command [ dict get $args -command ]
    dict unset args -command
  }
  label $name {*}$args -foreground blue -font Underline-Font
  if { [ info exists command ] } {
    bind $name <Button-1> $command
  }
  return $name
}

谁能帮帮我?

更新 2

我想要的是在我的 window 文本中显示超链接,就像这样:

更多信息在这些链接后给出:

显示第一个代码后,我可以显示: 使用的代码是:

我该怎么做才能得到我想要的?

注意第一次更新因版权保护已延迟

您可以使用找到的 proc。如果你有:

hyperlink .hl -command [list puts "clicked"] -text "Click Me"
pack .hl

在您的代码中单击 'hyperlink',您将得到文本 clicked 到标准输出。

如果要打开默认浏览器并转到 hyperlink 指定的 url,则必须将代码更改为:

hyperlink .hl -command [list eval exec [auto_execok start] "http://www.example.com"] -text "Click Me"
pack .hl

您也可以尝试一下 proc,也许可以更改字体大小(从 -size 12 开始)或更改字体本身。


Post编辑:

您可以通过将以下内容添加到 dispFile 过程中的开关来将 'hyperlink' 添加到您的代码中:

"<hypLink>" {
    gets $infile inln
    .fr.txt insert end "$inln" "link lk$lkcount"
    .fr.txt insert end "\n" Normal
    .fr.txt tag bind lk$lkcount <1> [list eval exec [auto_execok start] "$inln"]
    incr lkcount
}

这应该会创建类似于打开文件的文本,但不会打开文件,而是会在默认浏览器中打开 link。