r - R tkinsert 无法识别“\\n”
问题描述
新示例
在 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 上工作。
解决方案
这现在有效(至少在 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")
推荐阅读
- ruby - Watir运行错误
- python - Why use class method over a regular function in python
- python - 如何使用 Python 连接 SQLite DB 中的两个表?
- c++ - 将 CURL 作为静态库添加到 C++ CMake 项目
- android - 使用 minifyEnabled true 后的 android studio 错误
- android - Navigation Drawer 项目应该是静态的还是动态的?
- ubuntu - 无法在 ubuntu 16.04 上启动 meld,因为错误 import meld.conf
- listview - 无法将水平可滚动的 ListView 包装在 Column 中
- javascript - 浏览器中的 Wacom 取消移动
- python - 如何在python中提取部分字符串(字符串长度可能会有所不同)