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

  • 相关阅读:
    PHP mysqli_sqlstate() 函数
    修改用户家目录
    mysql 我的学习
    mysql 表空间
    mysql cluster 运行的必备条件
    浅谈mysql集群
    RBAC权限管理
    mysql 恢复备份
    oracle10G/11G官方下载地址集合 直接迅雷下载
    MySQL 全文搜索支持, mysql 5.6.4支持Innodb的全文检索和类memcache的nosql支持
  • 原文地址:https://www.cnblogs.com/anita-harbour/p/9333633.html
Copyright © 2011-2022 走看看