from PyQt5.QtWidgets import QWidget,QLabel,QLineEdit,QGroupBox,QGridLayout,QVBoxLayout,QPushButton,QMessageBox import pickle,pymssql,os,threading,time #定義數(shù)據(jù)庫(kù)窗口 class db_window(QWidget): def __init__(self): super().__init__() self.db_server = QLineEdit() self.db_port = QLineEdit() self.db_user = QLineEdit() self.db_password = QLineEdit() self.dir_db = {} #初始化數(shù)據(jù)庫(kù)鏈接信息 self.db_test_flag = -1 self.dir_test_db = {} self.initUI() self.initDB() def initUI(self): #初始化頁面 db_server_label = QLabel('數(shù)據(jù)庫(kù)地址:') db_port_label = QLabel('端口:') db_user_label = QLabel('數(shù)據(jù)庫(kù)賬號(hào):') db_password_label = QLabel('數(shù)據(jù)庫(kù)密碼:') self.db_password.setEchoMode(QLineEdit.Password) db_test_button = QPushButton('測(cè)試數(shù)據(jù)庫(kù)鏈接') db_input_button = QPushButton('保存數(shù)據(jù)庫(kù)鏈接') db_test_button.clicked.connect(self.test_db) db_input_button.clicked.connect(self.save_db) db_dbinfo_group = QGroupBox('MSSQL數(shù)據(jù)庫(kù)') db_mssql_grid = QGridLayout() db_mssql_grid.addWidget(db_server_label,0,0) db_mssql_grid.addWidget(db_port_label,0,1) db_mssql_grid.addWidget(db_user_label,0,2) db_mssql_grid.addWidget(db_password_label,0,3) db_mssql_grid.addWidget(db_test_button,0,4) db_mssql_grid.addWidget(self.db_server,1,0) db_mssql_grid.addWidget(self.db_port,1,1) db_mssql_grid.addWidget(self.db_user,1,2) db_mssql_grid.addWidget(self.db_password,1,3) db_mssql_grid.addWidget(db_input_button,1,4) db_dbinfo_group.setLayout(db_mssql_grid) vbox = QVBoxLayout() vbox.addWidget(db_dbinfo_group) self.test_label = QLabel('') vbox.addWidget(self.test_label) vbox.setStretchFactor(db_dbinfo_group,3) vbox.setStretchFactor(self.test_label,7) self.setLayout(vbox) #初始化數(shù)據(jù)庫(kù)鏈接信息 def initDB(self): try: if os.path.exists('.//DATA//DBinfo.pik'): with open('.//DATA//DBinfo.pik','rb') as db_file: self.dir_db = pickle.load(db_file) for line in self.dir_db.keys(): if line == 'server': self.db_server.setText(self.dir_db['server']) elif line == 'port': self.db_port.setText(str(self.dir_db['port'])) elif line == 'user': self.db_user.setText(self.dir_db['user']) elif line == 'password': self.db_password.setText(self.dir_db['password']) except Exception as error: return #數(shù)據(jù)庫(kù)測(cè)試按鈕 def test_db(self): self.dir_test_db.clear() if self.db_server.text().strip() != '': self.dir_test_db['server'] = self.db_server.text().strip() if self.db_port.text().strip() != '': try: port = int(self.db_port.text().strip()) except Exception as error: QMessageBox.warning(self,'端口錯(cuò)誤','名稱欄目:pyqt5_站點(diǎn)管理_db_windows
分享鏈接:http://aaarwkj.com/article34/psoose.html成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)公司、品牌網(wǎng)站制作、全網(wǎng)營(yíng)銷推廣、
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)