Python Forum
Upload file data on Qwidget
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Upload file data on Qwidget
#2
unknown encoding: mbcs

You can display and edit in QPlainTextEdit

from PyQt5 import QtGui, QtCore, QtWidgets
import os, sys
 
         
class MyWidget(QtWidgets.QMainWindow):
    def __init__(self):
        super(MyWidget, self).__init__()
        self.initUI()
     
    def initUI(self):
        self.setGeometry(600, 300, 450, 300)
        self.setWindowTitle('YAML Uploader Button')
        self.tool_bar = self.addToolBar("File")
        button = QtWidgets.QPushButton('upload a yaml', self)
        button.resize(button.sizeHint())
        button.clicked.connect(self.YamlUpload)
        self.tool_bar.addWidget(button)
        self.editor = QtWidgets.QPlainTextEdit()
        self.setCentralWidget(self.editor)
        self.show()
     
    def YamlUpload(self):
        filePath, _ = QtWidgets.QFileDialog.getOpenFileName(self, 'Single File', r'C:\Users\maiya\Desktop\compare', '*.yml')
        with open(filePath, 'r', encoding='utf-8') as file_pointer:
            self.lines = file_pointer.read()
            self.editor.setPlainText(self.lines)
 
def main():
    app = QtWidgets.QApplication(sys.argv)
    widget = MyWidget()
    app.exec_()
 
 
if __name__ == '__main__':
    main()
maiya likes this post
Reply


Messages In This Thread
Upload file data on Qwidget - by maiya - Jul-07-2022, 07:00 AM
RE: Upload file data on Qwidget - by Axel_Erfurt - Jul-07-2022, 01:19 PM
RE: Upload file data on Qwidget - by maiya - Jul-08-2022, 05:24 AM
RE: Upload file data on Qwidget - by maiya - Jul-08-2022, 05:35 AM
RE: Upload file data on Qwidget - by Axel_Erfurt - Jul-08-2022, 08:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] Seeking guidance on PyQt Instantiation and correct way to use an instance of QWidget BrewBarred 3 746 Jan-23-2024, 07:21 AM
Last Post: deanhystad
Video [PyQt] Get a executable file (.exe) from a .py file add a promoted class in a QWidget MiguelonReyes 0 761 Oct-17-2023, 11:43 PM
Last Post: MiguelonReyes

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020