import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from Dialog_ReadAndWriteTxt import *
from PyQt5.QtCore import QFile
class MyFrom(QDialog,Ui_Dialog_ReadAndWriteTxt):
def __init__(self):
super().__init__()
self.setupUi(self)
self.pushButton_Read.clicked.connect(self.Read_txt)
self.pushButton_Save.clicked.connect(self.Write_txt)
def Read_txt(self):
File_name = QFileDialog.getOpenFileName(self,"Open a txt file:","./","Txt(*.txt)")
if File_name[0]:
f = QFile(File_name[0])
f = open(File_name[0],"r")
with f:
File_this_data = f.read()
self.textEdit_txt.setText(File_this_data)
f.close()
def Write_txt(self):
File_name = QFileDialog.getSaveFileName(self,"Write to File:","./","Txt(*.txt)")
if File_name[0]:
f = open(File_name[0],"w")
with f:
Txt_File_data = self.textEdit_txt.toPlainText()
f.write(Txt_File_data)
f.close()
if __name__ == "__main__":
App = QApplication(sys.argv)
From = MyFrom()
From.show()
App.exec_()