Guest User

Untitled

a guest
Oct 21st, 2019
72
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from PyQt5.QtWidgets import QApplication, QWidget, QPlainTextEdit, QInputDialog,QLineEdit, QFileDialog, QGridLayout, QGroupBox, QLabel,QMessageBox, QPushButton
  2. from PyQt5.QtGui import QIcon, QPixmap
  3.  
  4. currentFile = ""
  5. editArea = None
  6. def on_open_button_clicked():
  7. global currentFile, editArea
  8. options = QFileDialog.Options()
  9. options |= QFileDialog.DontUseNativeDialog
  10. currentFile, _ = QFileDialog.getOpenFileName(widget,"Wybierz plik obrazu", "","Text Files (*.txt)", options=options)
  11. s = open(currentFile, 'r').read()
  12. editArea.setPlainText(s)
  13.  
  14.  
  15. def on_save_button_clicked():
  16. text = editArea.toPlainText()
  17. saveFilePath, _ = QFileDialog.getSaveFileName(None, "tytul", "name", None, None)
  18. print(saveFilePath)
  19. file = open(saveFilePath, "w")
  20. file.write(text)
  21. file.close()
  22.  
  23.  
  24.  
  25. app = QApplication([])
  26. horizontalGroupBox = QGroupBox("Nazwa grupy")
  27. layout = QGridLayout()
  28. widget = QWidget()
  29. widget.setWindowTitle("Title!!")
  30. openButton = QPushButton('Otworz plik')
  31. openButton.clicked.connect(on_open_button_clicked)
  32. saveButton = QPushButton('Zapisz plik')
  33. saveButton.clicked.connect(on_save_button_clicked)
  34. layout.addWidget(openButton)
  35. layout.addWidget(saveButton)
  36. editArea = QPlainTextEdit(widget)
  37. layout.addWidget(editArea)
  38.  
  39.  
  40. horizontalGroupBox.setLayout(layout)
  41. horizontalGroupBox.show()
  42. app.exec_()
RAW Paste Data