python用tkinter写的记事本,连续查找字符串函数,运行程序,结果能出来,但是窗口也死了

def find_char(self,event = None):
target = simpledialog.askstring("简易文本编辑器","寻找字符串")
if target:
end = self.st.index(tk.END)
print(end)
endindex = end.split(".")
end_line = int(endindex[0])
end_column = int(endindex[1])
pos_line =1
pos_column=0
length =len(target)
while pos_line <= end_line :
if pos_line == end_line and pos_column +length > end_column:
break
elif pos_line < end_line and pos_column + length >500:
pos_line = pos_line + 1
pos_column = (pos_column + length) -500
if pos_column > end_column:
break
else:
pos = str(pos_line)+"."+str(pos_column)
where = self.st.search(target,pos,tk.END)
if where:
print(where)
where1 =where.split(".")
sele_end_col = str(int(where1[1])+length)
sele = where1[0] + "."+ sele_end_col
self.st.tag_add(tk.SEL,where,sele)
self.st.mark_set(tk.INSERT,sele)
self.st.see(tk.INSERT)
self.st.focus()

                    again = messagebox.askokcancel(title = "继续查询么")
                    if again:
                        pos_line = int(where1[0])
                        pos_column = int(sele_end_col)
                    else:
                        aa=messagebox.showinfo(title = "你终于还是放弃了我",message = "你放弃了我--!")
                        if aa:
                            sys.exit()
查看全部
6facebeast
6facebeast
2016/05/12 11:22
  • 点赞
  • 收藏
  • 回答
    私信

2个回复