zoukankan      html  css  js  c++  java
  • 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上面已经通过

  • 相关阅读:
    类成员之静态字段和普通字段、静态方法和普通方法
    类的导出
    面向对象之继承
    面向对象之封装
    面向对象与函数式的对比
    计算器
    模拟信用卡登录程序
    /etc/fstab
    解决 Your project contains error(s),please fix them before running your applica ..
    C#之SqlDependency数据库缓存
  • 原文地址:https://www.cnblogs.com/anita-harbour/p/9333633.html
Copyright © 2011-2022 走看看