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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'xx.ui'
#
# Created by: PyQt5 UI code generator 5.11.2
#
# WARNING! All changes made in this file will be lost!
import sys
from PyQt5.QtWidgets import *
from F_Princ import Ui_F_Princ
from F_Secon import Ui_F_Secon
class AppWindow(QMainWindow):
def __init__(self):
super().__init__()
self.ui = Ui_F_Princ()
self.ui.setupUi(self)
self.show()
self.ui.pushButton.clicked.connect(self.fen_Addcombobox)
self.alim_combobox()
def fen_Addcombobox(self):
self.fen_Addcombobox = Addcombobox()
#Alimentter la combobox en Noms du fichier .txt
def alim_combobox(self):
with open('noms.txt','r') as noms:
for nom in noms:
self.ui.comboBox.addItem(str(nom.strip()))
#Affiche le nom de la combobox
self.ui.comboBox.currentIndexChanged.connect(self.aff_noms)
def aff_noms(self):
noms = self.ui.comboBox.currentText()
self.ui.lineEdit.setText(str(noms))
class Addcombobox(QMainWindow):
def __init__(self):
super().__init__()
self.ui = Ui_F_Secon()
self.ui.setupUi(self)
self.show()
self.ui.pB_add.clicked.connect(self.add)
self.ui.pB_del.clicked.connect(self.sup)
#lecture / ecriture (listwidget) les noms
with open('noms.txt','r') as noms:
for nom in noms:
self.ui.listWidget.sortItems()
self.ui.listWidget.addItem(str(nom.strip()))
def add(self):
add_noms = self.ui.lineEdit_add.text()
if len(add_noms) > 0:
self.ui.listWidget.addItem(str(add_noms))
#Ajout des Noms dans le fichier "noms.txt"
nomsTXT = open("noms.txt", "a")
nomsTXT.write(str(add_noms))
nomsTXT.write('\n')
nomsTXT.close()
self.ui.lineEdit_add.clear()
self.ui.listWidget.sortItems()
else:
print("la lineEdit est vierge")
def sup(self):
print("EN COURS")
app = QApplication(sys.argv)
w = AppWindow()
w.show()
sys.exit(app.exec_()) |
Partager