我正在使用TkInter中的文本小部件功能來「保存」行/段落並追加到列表中。避免訪問相同的位置兩次/單擊兩次,TkInter文本小部件
with open(fname1, "rt", encoding='latin1') as in_file:
readable_file = in_file.read()
line_list = []
def grab_line(event):
line_beginning = textPad.index("current linestart")
line_ending = textPad.index("current lineend")
line = textPad.get(line_beginning, line_ending)
line_list.append(line)
root = Tk()
frame = Frame(root, width=750, height=1)
root.minsize(600,600) # sets the size of the actual window
frame.pack()
text = Text(root)
text.insert(1.0, readable_file)
text.bind('<Button-1>', grab_line)
root.mainloop()
有沒有辦法確保我不會選擇同一段落兩次?也許有一個TkInter函數...
否則,人們會檢查列表/字典的內容,並刪除,如果有重複。
如果你的意思是在非常短的時間內雙擊,然後你就可以比較當前'line_beginning'與'previous_line_beginning' – furas
也許你應該使用'<雙鈕釦1>' – furas