Cześć,
Potrzebuję mieć możliwość zapisu w oddzielnym oknie numer i przypisania go do comboboxa, tyle że chce aby te wartości były zapamiętane przy każdym ponownym uruchomieniu.
Poniżej zamieszczam mój kod testowy.
from PyQt5.QtWidgets import QLabel,QDialogButtonBox,QTableWidget, QTableWidgetItem, QVBoxLayout, QPushButton, QAction, QLineEdit, QMessageBox, QDateEdit,QHBoxLayout, QGridLayout
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5 import QtWidgets, QtGui
class Klient1(QWidget):
def __init__(self):
super(Klient1, self).__init__()
self.setWindowTitle("Klient")
self.setFixedSize(300, 200)
self.initUI()
def initUI(self):
self.combobox = QtWidgets.QComboBox(self)
self.combobox.move(10,10)
self.combobox.resize(100,25)
self.btn = QtWidgets.QPushButton('otworz',self)
self.btn.clicked.connect(self.add)
self.btn.move(10,50)
self.btn.resize(100,25)
def add(self,nowe):
dodaj = Dodaj_zlecenie()
dodaj.exec_()
wartosc = (dodaj.numer)
self.combobox.addItem(wartosc)
dodaj.show()
class Dodaj_zlecenie(QDialog):
def __init__(self, *args, **kwargs):
super(Dodaj_zlecenie, self).__init__(*args, **kwargs)
self.QBtn = QPushButton()
self.QBtn.setText("Dodaj")
self.setWindowTitle("Dodaj do listy")
self.setFixedWidth(300)
self.setFixedHeight(100)
self.QBtn.clicked.connect(self.nowe)
layout = QVBoxLayout()
#
self.listinput = QLineEdit()
self.onlyInt = QIntValidator()
self.listinput.setValidator(self.onlyInt)
self.listinput.setPlaceholderText("Numer.")
layout.addWidget(self.listinput)
layout.addWidget(self.QBtn)
self.setLayout(layout)
def nowe(self):
global numer
self.numer = (self.listinput.text())
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
app.setStyle('Fusion')
MW = Klient1()
MW.show()
sys.exit(app.exec_())