0

新示例

在 user2554330 发表评论后,我正在更新问题。由于我更新了 R 版本,包 tcltk 中的 tkinsert 函数无法识别标志“\n”。我怎样才能写出不同的行?

新的例子。这是一个曾经有效的真实示例,写了 3 行星号和 3 行空行:

library(tcltk)
tt <- tktoplevel()
tkpack(txt.w <- tktext(tt))
endL <- paste0("***************************************", 
           "*************************")
tcltk::tkinsert(txt.w , "end", endL, collapse = "\\n")
tcltk::tkinsert(txt.w , "end", endL, collapse = "\\n")
tcltk::tkinsert(txt.w , "end", endL, collapse = "\\n")
tcltk::tkinsert(txt.w , "end", paste("\\n\\n"))
tcltk::tkinsert(txt.w , "end", paste("\\n\\n"))
tcltk::tkinsert(txt.w , "end", paste("\\n\\n"))

现在我明白了(我用点替换多个星号,否则消息无法正确显示)。

" ... \n **************... \n *****...***\n\n\n\n\n\n\n "

而不是三行星号和三行空行。

其实我可以写这个,但结果是一样的。

library(tcltk)
tt <- tktoplevel()
tkpack(txt.w <- tktext(tt))
endL <- paste0("***************************************", 
           "*************************")
tcltk::tkinsert(txt.w , "end", endL, collapse = "\\n")
tcltk::tkinsert(txt.w , "end", endL, collapse = "\\n")
tcltk::tkinsert(txt.w , "end", endL, collapse = "\\n")
tcltk::tkinsert(txt.w , "end", "\\n\\n")
tcltk::tkinsert(txt.w , "end", "\\n\\n")
tcltk::tkinsert(txt.w , "end", "\\n\\n")

使用这个其他版本,结果仍然相同

library(tcltk)
tt <- tktoplevel()
tkpack(txt.w <- tktext(tt))
endL <- paste0("***************************************", 
           "*************************")
tcltk::tkinsert(txt.w , "end", endL, collapse = "\\n")
tcltk::tkinsert(txt.w , "end", endL, collapse = "\\n")
tcltk::tkinsert(txt.w , "end", endL, collapse = "\\n")
tcltk::tkinsert(txt.w , "end", "\\n")
tcltk::tkinsert(txt.w , "end", "\\n")
tcltk::tkinsert(txt.w , "end", "\\n")

老例子

由于我更新了 R 版本,包 tcltk 中的 tkinsert 函数无法识别标志“\n”。我想写不同的行,但是“\n”不起作用,其他选项也不起作用(我得到的所有数字都像这样:OneTwoThreeFourFiveSix.

tt <- tktoplevel()
tkpack(txt.w <- tktext(tt))
tcltk::tkinsert(txt.w, "end", paste("One", collapse = "\\n"))
tcltk::tkinsert(txt.w, "end", paste("Two", collapse = "\n"))
tcltk::tkinsert(txt.w, "end", paste("Three", collapse = "\n\r"))
tcltk::tkinsert(txt.w, "end", paste("Four", collapse = "\t"))
tcltk::tkinsert(txt.w, "end", paste("Five", collapse = "\\t"))
tcltk::tkinsert(txt.w, "end", paste("Six", collapse = "\r\n"))

我在 Windows 上工作。

4

1 回答 1

0

这现在有效(至少在 Windows 上):

library(tcltk)
tt <- tktoplevel()
tkpack(txt.w <- tktext(tt))

endL <- paste0("***************************************", 
           "*************************")
tcltk::tkinsert(txt.w, "end", endL, collapse = "\n")
tcltk::tkinsert(txt.w, "end", endL, collapse = "\n")
tcltk::tkinsert(txt.w, "end", endL, collapse = "\n")
tcltk::tkinsert(txt.w, "end", "\n\n")
tcltk::tkinsert(txt.w, "end", "\n\n")
tcltk::tkinsert(txt.w, "end", "\n\n")

这也有效:

library(tcltk)
tt <- tktoplevel()
tkpack(txt.w <- tktext(tt))

endL <- paste0("***************************************", 
           "*************************")
tcltk::tkinsert(txt.w, "end", endL)
tcltk::tkinsert(txt.w, "end", "\n")
tcltk::tkinsert(txt.w, "end", endL)
tcltk::tkinsert(txt.w, "end", "\n")
tcltk::tkinsert(txt.w, "end", endL)
tcltk::tkinsert(txt.w, "end", "\n")
tcltk::tkinsert(txt.w, "end", "\n\n")
tcltk::tkinsert(txt.w, "end", "\n\n")
tcltk::tkinsert(txt.w, "end", "\n\n")

现在工作的旧示例:

tt <- tktoplevel()
tkpack(txt.w <- tktext(tt))
tcltk::tkinsert(txt.w, "end", "One", collapse = "\n")
tcltk::tkinsert(txt.w, "end", "Two", collapse = "\n")
tcltk::tkinsert(txt.w, "end", "Three", collapse = "\n")
tcltk::tkinsert(txt.w, "end", "Four", collapse = "\n")
tcltk::tkinsert(txt.w, "end", "Five", collapse = "\n")
tcltk::tkinsert(txt.w, "end", "Six", collapse = "\n")
于 2020-12-05T09:58:26.070 回答