欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PYQT5實現(xiàn)控制臺顯示功能的方法

 更新時間:2019年06月25日 12:00:44   作者:晚安丶  
今天小編大家分享一篇PYQT5實現(xiàn)控制臺顯示功能的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

界面文件 Ui_ControlBoard.py

# -*- coding: utf-8 -*-
 
# Form implementation generated from reading ui file 'Ui_ControlBoard.ui'
#
# Created by: PyQt5 UI code generator 5.11.3
#
# WARNING! All changes made in this file will be lost!
 
from PyQt5 import QtCore, QtWidgets
 
class Ui_MainWindow(object):
  def setupUi(self, MainWindow):
    MainWindow.setObjectName("MainWindow")
    MainWindow.resize(800, 600)
    self.centralwidget = QtWidgets.QWidget(MainWindow)
    self.centralwidget.setObjectName("centralwidget")
    self.textBrowser = QtWidgets.QTextBrowser(self.centralwidget)
    self.textBrowser.setGeometry(QtCore.QRect(50, 180, 591, 171))
    self.textBrowser.setObjectName("textBrowser")
    self.pushButton = QtWidgets.QPushButton(self.centralwidget)
    self.pushButton.setGeometry(QtCore.QRect(450, 390, 93, 28))
    self.pushButton.setObjectName("pushButton")
    MainWindow.setCentralWidget(self.centralwidget)
    self.menubar = QtWidgets.QMenuBar(MainWindow)
    self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
    self.menubar.setObjectName("menubar")
    MainWindow.setMenuBar(self.menubar)
    self.statusbar = QtWidgets.QStatusBar(MainWindow)
    self.statusbar.setObjectName("statusbar")
    MainWindow.setStatusBar(self.statusbar)
 
    self.retranslateUi(MainWindow)
    QtCore.QMetaObject.connectSlotsByName(MainWindow)
 
  def retranslateUi(self, MainWindow):
    _translate = QtCore.QCoreApplication.translate
    MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
    self.pushButton.setText(_translate("MainWindow", "PushButton"))
 

邏輯文件 Call_ControlBoard.py

版本一

#!/usr/bin/env python3
# -*- coding:utf-8 -*- 
from PyQt5 import QtCore, QtGui
import sys
from PyQt5.QtCore import QEventLoop, QTimer
from PyQt5.QtWidgets import QApplication, QMainWindow
 
from Ui_ControlBoard import Ui_MainWindow
 
class EmittingStr(QtCore.QObject):
    textWritten = QtCore.pyqtSignal(str) #定義一個發(fā)送str的信號
    def write(self, text):
      self.textWritten.emit(str(text))
 
 
class ControlBoard(QMainWindow, Ui_MainWindow):
  def __init__(self):
    super(ControlBoard, self).__init__()
    self.setupUi(self)
    # 下面將輸出重定向到textBrowser中
    sys.stdout = EmittingStr(textWritten=self.outputWritten)
    sys.stderr = EmittingStr(textWritten=self.outputWritten)
 
 
    self.pushButton.clicked.connect(self.bClicked)
 
  def outputWritten(self, text):
    cursor = self.textBrowser.textCursor()
    cursor.movePosition(QtGui.QTextCursor.End)
    cursor.insertText(text)
    self.textBrowser.setTextCursor(cursor)
    self.textBrowser.ensureCursorVisible()
 
  def bClicked(self):
    """Runs the main function."""
    print('Begin')
    loop = QEventLoop()
    QTimer.singleShot(1000, loop.quit)
    loop.exec_()
    self.printABCD()
    loop = QEventLoop()
    QTimer.singleShot(1000, loop.quit)
    loop.exec_()
    print("End")
 
  def printABCD(self):
    print("aaaaaaaaaaaaaaaa")
    print("bbbbbbbbbbbbbbbb")
    print("cccccccccccccccc")
    print("dddddddddddddddd")
 
 
 
 
if __name__ == "__main__":
  app = QApplication(sys.argv)
  win = ControlBoard()
  win.show()
  sys.exit(app.exec_())

版本二

#!/usr/bin/env python3
# -*- coding:utf-8 -*- 
from PyQt5 import QtCore, QtGui
import sys
from PyQt5.QtCore import QEventLoop, QTimer
from PyQt5.QtWidgets import QApplication, QMainWindow
 
from Ui_ControlBoard import Ui_MainWindow
 
class EmittingStr(QtCore.QObject):
    textWritten = QtCore.pyqtSignal(str) #定義一個發(fā)送str的信號
    def write(self, text):
      self.textWritten.emit(str(text))
      loop = QEventLoop()
      QTimer.singleShot(1000, loop.quit)
      loop.exec_()
 
 
class ControlBoard(QMainWindow, Ui_MainWindow):
  def __init__(self):
    super(ControlBoard, self).__init__()
    self.setupUi(self)
    # 下面將輸出重定向到textBrowser中
    sys.stdout = EmittingStr(textWritten=self.outputWritten)
    sys.stderr = EmittingStr(textWritten=self.outputWritten)
 
 
    self.pushButton.clicked.connect(self.bClicked)
 
  def outputWritten(self, text):
    cursor = self.textBrowser.textCursor()
    cursor.movePosition(QtGui.QTextCursor.End)
    cursor.insertText(text)
    self.textBrowser.setTextCursor(cursor)
    self.textBrowser.ensureCursorVisible()
 
  def bClicked(self):
    """Runs the main function."""
    print('Begin')
 
    self.printABCD()
 
    print("End")
 
  def printABCD(self):
    print("aaaaaaaaaaaaaaaa")
    print("bbbbbbbbbbbbbbbb")
    print("cccccccccccccccc")
    print("dddddddddddddddd")
 
 
 
 
if __name__ == "__main__":
  app = QApplication(sys.argv)
  win = ControlBoard()
  win.show()
  sys.exit(app.exec_())

版本三

#!/usr/bin/env python3
# -*- coding:utf-8 -*- 
from PyQt5 import QtCore, QtGui
import sys
from PyQt5.QtCore import QEventLoop, QTimer
from PyQt5.QtWidgets import QApplication, QMainWindow
 
from Ui_ControlBoard import Ui_MainWindow
 
class EmittingStr(QtCore.QObject):
    textWritten = QtCore.pyqtSignal(str) #定義一個發(fā)送str的信號
    def write(self, text):
      self.textWritten.emit(str(text))
 
 
class ControlBoard(QMainWindow, Ui_MainWindow):
  def __init__(self):
    super(ControlBoard, self).__init__()
    self.setupUi(self)
    # 下面將輸出重定向到textBrowser中
    sys.stdout = EmittingStr(textWritten=self.outputWritten)
    sys.stderr = EmittingStr(textWritten=self.outputWritten)
 
 
    self.pushButton.clicked.connect(self.bClicked)
 
  def outputWritten(self, text):
    cursor = self.textBrowser.textCursor()
    cursor.movePosition(QtGui.QTextCursor.End)
    cursor.insertText(text)
    self.textBrowser.setTextCursor(cursor)
    self.textBrowser.ensureCursorVisible()
 
  def bClicked(self):
    """Runs the main function."""
    print('Begin')
 
    self.printABCD()
 
    print("End")
 
  def printABCD(self):
    print("aaaaaaaaaaaaaaaa")
    print("bbbbbbbbbbbbbbbb")
    print("cccccccccccccccc")
    print("dddddddddddddddd")
 
 
 
 
if __name__ == "__main__":
  app = QApplication(sys.argv)
  win = ControlBoard()
  win.show()
  sys.exit(app.exec_())

以上這篇PYQT5實現(xiàn)控制臺顯示功能的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python集合union()函數(shù)使用實例詳解

    Python集合union()函數(shù)使用實例詳解

    union()方法的工作原理是:返回多個集合(集合的數(shù)量大于等于2)的并集,即結(jié)果集合包含了所有被合并集合中的所有元素,因為集合中的元素不可重復,所以各個集合中重復的元素在結(jié)果集合中只會出現(xiàn)一次,本文將簡單介紹一下Python union()函數(shù)使用方法
    2023-07-07
  • 解決python中os.listdir()函數(shù)讀取文件夾下文件的亂序和排序問題

    解決python中os.listdir()函數(shù)讀取文件夾下文件的亂序和排序問題

    今天小編就為大家分享一篇解決python中os.listdir()函數(shù)讀取文件夾下文件的亂序和排序問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-10-10
  • 利用python進行接口測試及類型介紹

    利用python進行接口測試及類型介紹

    這篇文章主要介紹了利用python進行接口測試詳情,文章基于python展開對接口測試的詳細介紹,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-05-05
  • Python+streamlit實現(xiàn)輕松創(chuàng)建人事系統(tǒng)

    Python+streamlit實現(xiàn)輕松創(chuàng)建人事系統(tǒng)

    streamlit 是 基于 Python 的一個非常強大的 web 構(gòu)建系統(tǒng),通過該類庫,我們可以實現(xiàn)不需要編寫一行前端代碼而構(gòu)建一個完整的 Web 應用。下面我們就來編寫一個簡單的人事系統(tǒng)吧
    2023-02-02
  • pydantic-resolve嵌套數(shù)據(jù)結(jié)構(gòu)生成LoaderDepend管理contextvars

    pydantic-resolve嵌套數(shù)據(jù)結(jié)構(gòu)生成LoaderDepend管理contextvars

    這篇文章主要為大家介紹了pydantic-resolve解決嵌套數(shù)據(jù)結(jié)構(gòu)生成LoaderDepend管理contextvars的使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪<BR>
    2023-04-04
  • tensorflow通過模型文件,使用tensorboard查看其模型圖Graph方式

    tensorflow通過模型文件,使用tensorboard查看其模型圖Graph方式

    今天小編就為大家分享一篇tensorflow通過模型文件,使用tensorboard查看其模型圖Graph方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-01-01
  • Python 實現(xiàn)在文件中的每一行添加一個逗號

    Python 實現(xiàn)在文件中的每一行添加一個逗號

    下面小編就為大家分享一篇Python 實現(xiàn)在文件中的每一行添加一個逗號,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-04-04
  • Python如何根據(jù)字典中的值排序

    Python如何根據(jù)字典中的值排序

    這篇文章主要介紹了Python如何根據(jù)字典中的值排序問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-02-02
  • Python多線程的使用詳情

    Python多線程的使用詳情

    這篇文章主要介紹了Python多線程的使用詳情,線程之間執(zhí)行是無序的,cpu調(diào)度哪個線程就執(zhí)行哪個線程,下文相關(guān)介紹需要的小伙伴可以參考一下
    2022-04-04
  • python得到一個excel的全部sheet標簽值方法

    python得到一個excel的全部sheet標簽值方法

    今天小編就為大家分享一篇python得到一個excel的全部sheet標簽值方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-12-12

最新評論