In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
From PyQt5.QtWidgets import QWidget,QLabel,QLineEdit,QGroupBox,QGridLayout,QVBoxLayout,QPushButton,QMessageBoximport pickle,pymssql,os,threading Time# defines the database window 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 = {} # initialize the database chain Receive the message self.db_test_flag =-1 self.dir_test_db = {} self.initUI () self.initDB () def initUI (self): # initialization page db_server_label = QLabel ('database address:') db_port_label = QLabel ('port:') db_user_label = QLabel ('data Library account:') db_password_label = QLabel ('database password:') self.db_password.setEchoMode (QLineEdit.Password) db_test_button = QPushButton ('test database link') db_input_button = QPushButton ('save database link') db_test_button.clicked.connect (self.test_db) db_input_button.clicked.connect (self.save_db) db_dbinfo_group = QGroupBox ('MSSQL database') db_mssql_grid = QGridLayout () db_mssql_grid.addWidget (db_server_label 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) 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) 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) # initialize database link information 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 # database test button 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) 'Port error', 'server port is a number, you typed it incorrectly.') Return self.dir_test_db ['port'] = port if self.db_user.text (). Strip ()! ='': self.dir_test_db ['user'] = self.db_user.text (). Strip () if self.db_password.text (). Strip ()! ='': self.dir_test_db ['password'] = self. Db_password.text () .strip () try: conn = pymssql.connect (* * self.dir_test_db) except Exception as error: QMessageBox.warning (self 'error', 'unable to link database.') Return self.test_label.setText ('') QMessageBox.about (self,' link succeeded', database link succeeded.) Self.db_test_flag = 1 conn.close () # Database Save button def save_db (self): if self.db_test_flag < 0: QMessageBox.warning (self,' prompt', 'you need to test the database link before saving the database information.\ nThe database link is normal before saving the information.') Return self.dir_db = self.dir_test_db.copy () with open ('. / / DATA//DBinfo.pik','wb') as db_file: pickle.dump (self.dir_db, db_file) self.db_test_flag =-1 QMessageBox.about (self,' prompt', 'message saved successfully.')
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.