我正在制作一个基本的文本编辑器,并在关闭程序时将滚动位置保存在文件中。然后,当打开程序时,它将从文件中读取滚动位置并更新它,以便您可以从上次停下的地方继续。
我可以获得scrolledtext.yview()返回元组的位置,例如 (0.42, 0.75)
但我不知道如何更改滚动位置。我试图scrolledtext.vbar.set(0.42, 0.75)尝试更新它,但这不起作用,因为它没有做任何事情并且没有给出任何错误。我也尝试过scrolledtext.yview(0.42, 0.75),但它说TclError: bad option "0.42": must be moveto or scroll如果有人知道如何更新它,将不胜感激,干杯。
编辑(代码):
import tkinter as tk
root = tk.Tk()
Frame = frame(root)
Frame.pack()
textbox = ScrolledText(Frame)
textbox.pack()
textbox.yview() #this is saved to file, produces tuple of e.g. (0.42, 0.75)
textbox.vbar.set(0.3, 0.7) #this doesn't produce any errors but doesn't change the scroll position
textbox.yview(0.3, 0.7) #this is also something i have tried but produces the error _tkinter.TclError: bad option …Run Code Online (Sandbox Code Playgroud) 我正在使用freecodecamp.com,任务是查找字符串中最长的单词,我收到此错误,我无法理解为什么我也查看了其他项目.
"TypeError:无法获取未定义或空引用的属性'长度'"
它指的是 copy[i].length
function findLongestWord(str) {
var copy = str;
copy = copy.split(' ');
var longest = 0;
for (var i = 0;i < copy.length;i++);
{
if (longest < copy[i].length)
{
longest = copy[i].length;
}
}
return longest;
}
findLongestWord("The quick brown fox jumped over the lazy dog");Run Code Online (Sandbox Code Playgroud)