python - 使用 PyQt5 在文本框中打印输出语句

标签 python python-3.x pyqt pyqt5

我创建了一个小部件,小部件的过程从输入 SQL.table_name 开始,然后切换 Run_analysis 按钮以生成 csv.file 格式的输出。上述过程表现良好。但我坚持在较大的文本框中打印(打印)语句。

enter image description here

class EpiClass:
    NR = 0
    R = 0
    CT = 0
    def __init__(self, obj):
        self.obj = obj
    def epi_calc(self):
        """Function to process EPI formula"""
        with open(FN, "w") as FL: #FN object FL
            for j in self.obj:
                if j[12] is not None and float(j[12]) != 0: #Exclude (Null, 0) values in Cre-j[12]
                    j12 = float(j[12])
                    type(j12)
                    #type(j[12]) #tested
                    #type(j[35]) #tested
                  {
                    Body of statement, assume it add two variable
                  }

        print("Total no of rows affected:", EpiClass.CT)
        print("No. of records not analysed:", EpiClass.NR)
        print("No. of records analysed:", EpiClass.R)

这里我们转到 PyQt5。

class WinClass(QMainWindow):
    """Main Window"""
    def __init__(self):
        super().__init__()
        self.title = 'EGFR Widget'
        self.left = 10
        self.top = 10
        self.width = 1920
        self.height = 1080
        self.init_ui()
    def init_ui(self):
        """Window Geometry"""
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        #label
        # Create textbox
        self.textbox = QLineEdit(self)
        self.textbox.move(20, 20)
        self.textbox.resize(280, 40)
        # Create a button in the window
        self.button = QPushButton('Run Analysis', self)
        self.button.move(20, 80)
        #Print affected Rows
        self.textbox2 = QLineEdit(self)
        self.textbox2.move(120, 120)
        self.textbox2.resize(880, 140)
        # connect button to function on_click
        self.button.clicked.connect(self.on_click)
        self.show()

    @pyqtSlot()
    def on_click(self):
        """Button Action function"""
        tb_value = str(self.textbox.text())
        new_class = Edb(tb_value)
        new_class.eclass()
######Im messed up in this step to print that 3 statements in textbox2#############
        tb2_value = str(self.textbox2.text(EpiClass.CT))
        #tb3_value = str(self.textbox2.text(EpiClass.NR))
        #tb4_value = str(self.textbox2.text(EpiClass.R))

if __name__ == '__main__':
    APP = QApplication(sys.argv)
    ex = WinClass()
    sys.exit(APP.exec_())

请建议一个代码来解决打印语句。非常感谢!

最佳答案

您正在尝试使用只读方法text进行写入,您应该使用setText。我会将这些语句保存在某个变量中并从您的小部件访问,但这取决于您。我希望它有帮助。

def on_click(self):
    """Button Action function"""
    tb_value = "Total no of rows affected: {}".format(EpiClass.CT)
    self.textbox2.setText(tb_value)

关于python - 使用 PyQt5 在文本框中打印输出语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58990893/

相关文章:

python - PyQt4中PYSIGNAL定义了什么模块

c++ - 自定义 QDockWidget 显示

python - 即使基本情况是完美的,递归也不会终止

python - django-cors-headers 根本不工作

python - Matplotlib 文本不采用数组值

python-3.x - 混淆矩阵获得精度、召回率、f1 分数

python循环requests.get()只返回第一个循环

python - 我将如何在实时场景中使用 concurrent.futures 和队列?

python - PyQt5 QWidget 将固定宽度设置为最小可用尺寸

Python 多处理性能仅随所用内核数的平方根提高