python Tkinter的Text组件中创建x轴和y轴滚动条,并且text文本框自动更新(二)
开两个窗口
# encoding: utf-8 import time from Tkinter import * class log(): def write_log_windows(self,file1, file2): with open(file1) as f1: self.windows1() self.windows2() for line in f1: f2 = open(file2, 'a+') f2.write(line) self.textpad1.insert(END, line) self.textpad2.insert(END, line) self.textpad1.see(END) self.textpad2.see(END) self.root1.update() self.root2.update() def windows1(self): self.root1 = Tk() self.root1.title("serial log") s1 = Scrollbar(self.root1) s1.pack(side=RIGHT, fill=Y) s2 = Scrollbar(self.root1, orient=HORIZONTAL) s2.pack(side=BOTTOM, fill=X) self.textpad1 = Text(self.root1, yscrollcommand=s1.set, xscrollcommand=s2.set, wrap='none') self.textpad1.pack(expand=YES, fill=BOTH) s1.config(command=self.textpad1.yview) s2.config(command=self.textpad1.xview) self.textpad1.pack() def windows2(self): self.root2 = Tk() self.root2.title("serial log") s1 = Scrollbar(self.root2) s1.pack(side=RIGHT, fill=Y) s2 = Scrollbar(self.root2, orient=HORIZONTAL) s2.pack(side=BOTTOM, fill=X) self.textpad2 = Text(self.root2, yscrollcommand=s1.set, xscrollcommand=s2.set, wrap='none') self.textpad2.pack(expand=YES, fill=BOTH) s1.config(command=self.textpad2.yview) s2.config(command=self.textpad2.xview) self.textpad2.pack() if __name__ == '__main__': file1 = 'log.txt' file2 = 'result.txt' d = log() d.write_log_windows(file1, file2)
Python2.7.9上面已经通过