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上面已经通过

转载于:https://www.cnblogs.com/anita-harbour/p/9333633.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值