python - pyqt Qtextbrowser 更新

标签 python pyqt qtextbrowser

def sort_domain():
    if self.cb1.isChecked():
        for line in f:
            line= line.strip()
            if line.endswith('.com') is True:
                self.textBrowser.append(line)
            else:
                pass
    elif not self.cb1.isChecked() and not self.cb2.isChecked():
        for line in f:
            line=line.strip()
            self.textBrowser.append(line)
    if self.cb2.isChecked():
        for line in f:
            line= line.strip()
            if line.endswith('.net') is True:
                self.textBrowser.append(line)
            else:
                pass
    elif not self.cb1.isChecked() and not self.cb2.isChecked():
        for line in f:
            line=line.strip()
            self.textBrowser.append(line)

self.btn2.clicked.connect(sort_domain)

如果我检查了cb1和cb2((checkbox1和chekbok2)) 结果是所有仅扩展名为 .com 的域。

当您按下 chekBox1“.com”和 chekBox2“.net”时,编写显示所有域的函数的正确方法是什么?

code and window

最佳答案

您的实现效率并不高:它多次读取文件的内容。这也是你程序的问题。在第一个 for 循环之后,文件对象指向文件末尾,要使其工作,您必须再次寻找开头:f.seek(0)

关于python - pyqt Qtextbrowser 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35025319/

相关文章:

python - __str__ 来 self 自己的矩阵,python

python - 删除字符串的最后 3 个字符

python - 如何在QTextBrowser中显示可点击的超链接

qt - 如何使链接在QTextEdit中可点击?

c++ - 如何从 QSS 选择 QTextBrowser 中的 href 标签?

python - 如何在Python中通过请求循环调用API

python - Dockerfile在项目目录中运行python脚本文件

python - 同时为两个或更多小部件提供悬停效果?

c++ - 如何将隐藏的数据发送到pyqt中的QComboBOX

python - 为 PyQt5 QCalendarWidget 单元格着色并打印单元格内的数据