1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| # coding: utf-8
import os
import os.path
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from design import Ui_Form
import resource
class main(QWidget, Ui_Form, object):
def __init__(self):
QWidget.__init__(self)
self.setupUi(self)
self.btn1.clicked.connect(self.write_to_file)
self.load_file()
def write_to_file(self):
with open(":/files/Myfile.txt","r+") as f:
a=self.txb1.text()
f.write(a)
f.close()
def load_file(self):
with open(":/files/Myfile.txt","r") as f:
b=f.readline()
self.lab1.setText(b)
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
Form = main()
Form.show()
sys.exit(app.exec_())
app = QApplication(sys.argv)
app.exec_() |
Partager