PyQt5 (2), garbage applet (2) - the first generation of windows executable files

Another day time (not any bigger jobs). Today's mentality: (1) how to connect the rear end of the front? (2) back-end database interpolated data (3) on the dictionary prior to completely useless reverse lookup method (4) suddenly found that use object-oriented programming is actually very good, even with the more addictive (5) QLineEdit, QInputDialog, QGridLayout (6) with clicked.connect () key trigger "event" (7) designed to connect to the database function, QtSql (8) QSqlDatabase, QSqlQuery two small things can really let me step on a lot of the pit (9) stepped on a few classes Code  Query the QSqlQuery = ()  "instantiated",  query.prepare (F ' SELECT Rclassification from Rub_cl WHERE RNAME = "{text}" ' )  double quotes extreme critical,  query.next ()  sense (10) with the last lazy pyinstaller even a cursory packaged as .exe hh. Note that because it comes with the need to use the database -D way.

Garbage applet probably came to an end. While there are many places can be optimized, there are still a lot of idea in my mind, but at least now I do not want to be lazy (break out laughing). Yesterday saw a completed micro-channel applet, doing really good, I feel I have reached the extreme can think of (micro-channel search applet: "how to divide garbage"). Really good, I still have a long way to go.

 

 1 import sys, sqlite3
 2 #from PyQt5.QtWidgets import (QWidget, QPushButton, QLabel, QLineEdit, QInputDialog, QApplication, QGridLayout)
 3 from PyQt5.QtWidgets import *
 4 from PyQt5 import QtSql
 5 from PyQt5.QtSql import *
 6 #from PyQt5.QtSql import QSqlDatabase, QSqlQuery
 7 
 8 class Example(QWidget):
 9     def __init__(self):
10         super().__init__()
11         self.initUI()
12 
13     def initUI(self):
14         self.btn = QPushButton('Start',self)#按钮
15         self.btn.clicked.connect(self.showDialog)
16 
17         self.le = QLineEdit(self)#单行编辑框
18 
19         text = QLabel('')
20 
21         self.answer = QLineEdit(self)
22 
23         grid = QGridLayout()
24         grid.setSpacing(10)
25 
26         grid.addWidget (self.btn, 1,0,1,3) # The last two parameters can be set ranks span. Here is a line ranks span of three. 
27          grid.addWidget (self.le, 2 , 0)
 28          grid.addWidget (text, 2,1 )
 29          grid.addWidget (self.answer, 2,2 & )
 30  
31 is          self.setLayout (Grid)
 32  
33 is          self.setGeometry (300,300,350,350 )
 34 is          self.setWindowTitle ( ' the Input Dialog ' )
 35          self.show ()
 36  
37 [      DEF the showDialog (Self):
 38 is          Global text
 39         text, ok = QInputDialog.getText(self, 'Input Dialog', 'Enter the rubbish:')
40         if ok:
41             self.le.setText(str(text))
42             self.showAnswer()
43 
44     def showAnswer(self):
45         db = QSqlDatabase.addDatabase('QSQLITE')
46         db.setDatabaseName('Rubbish.db')
47         db.open()
48         query = QSqlQuery()
49         query.prepare (F ' SELECT Rclassification from Rub_cl WHERE RNAME = "{text}" ' ) is a double quotation mark key #
 50          Query. Exec ()
 51 is          # query.next () 
52 is          # Print (Query.value (0)) 
53 is          IF  Not Query. Exec ():
 54 is              query.lastError () # returns the last error message 
55          the else :
 56 is              query.next ()
 57 is              ' '' 
58              the QSqlQuery return data set, record is stopped before the first record .
59              Therefore, after obtaining the data set must be performed next () or first () to the first record,
 60             This time record is valid.
61 is              ' '' 
62 is              answertoprint = Query.value (0)
 63 is              self.answer.setText (STR (answertoprint))
 64          
65          
66  
67  IF  the __name__ == ' __main__ ' :
 68  
69      App = the QApplication (the sys.argv)
 70      EX = example ()
 71 is      the sys.exit (app.exec_ ())

pyinstaller command line:

cd blablablablabla
pyinstaller -D(-F) -i icon.ico rubbish_classification.py

Several URL supplemented afraid I'll forget:

ico icon: https: //www.easyicon.net/

Qt Documentation:https://doc.qt.io/qt-5/qsqlquery.html

QMessageBox类 Doc:http://www.kuqin.com/qtdocument/qmessagebox.html

DevDocs API Documentation (think No developer documentation, I do not know why to be able to retain a say): https: //docs.segmentfault.com/

 

 

 

 

I'll certainly bigger job :-)

Guess you like

Origin www.cnblogs.com/hsh17/p/10977288.html