How do i run this normally I'm using python? [closed]Python list comparison: Can this code run faster?I think...
Did arcade monitors have same pixel aspect ratio as TV sets?
Drawing ramified coverings with tikz
Has any country ever had 2 former presidents in jail simultaneously?
MAXDOP Settings for SQL Server 2014
We have a love-hate relationship
Why do IPv6 unique local addresses have to have a /48 prefix?
Does a 'pending' US visa application constitute a denial?
Freedom of speech and where it applies
Bob has never been a M before
How do I nest cases?
Is it possible to have a strip of cold climate in the middle of a planet?
THT: What is a squared annular “ring”?
Engineer refusing to file/disclose patents
Is camera lens focus an exact point or a range?
Folder comparison
How should I respond when I lied about my education and the company finds out through background check?
Is a model fitted to data or is data fitted to a model?
Why has "pence" been used in this sentence, not "pences"?
What linear sensor for a keyboard?
Why is it that I can sometimes guess the next note?
Do varchar(max), nvarchar(max) and varbinary(max) columns affect select queries?
Is a file system driver implemented using a kernel module in Linux?
What is the grammatical term for “‑ed” words like these?
Is XSS in canonical link possible?
How do i run this normally I'm using python? [closed]
Python list comparison: Can this code run faster?I think I'm not using Try Except properly in this Python codeRun external command from PythonSurveillance software using python and pyqtRun multiple python codes and Check with answer dataMy Hangman game created using PyQt5 and Python 3.5Example of multithreading in Python3 / PyQt5 using QThreadDice roll simulator (updated) created using Python 3.5 and PyQt5Vigenère Cipher in Python, how secure is this?How good is this cipher? (Python)
$begingroup$
import sys
from PyQt5 import QtWidgets
from PyQt5.QtSql import QSqlQuery, QSqlDatabase
from PyQt5.QtCore import Qt, QModelIndex
from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QPushButton, QTableWidget, QTableWidgetItem, QMessageBox, QHBoxLayout, QLineEdit, QLabel, QGridLayout
class Login(QtWidgets.QDialog):
def __init__(self, parent=None):
super(Login, self).__init__(parent)
self.textName = QtWidgets.QLineEdit(self)
self.textPass = QtWidgets.QLineEdit(self)
self.buttonLogin = QtWidgets.QPushButton('Login', self)
self.buttonLogin.clicked.connect(self.handleLogin)
layout = QtWidgets.QVBoxLayout(self)
layout.addWidget(self.textName)
layout.addWidget(self.textPass)
layout.addWidget(self.buttonLogin)
def handleLogin(self):
if (self.textName.text() == 'admin' and
self.textPass.text() == 'admin'):
self.accept()
else:
QtWidgets.QMessageBox.warning(
self, 'Error', 'Try Again')
class Sign_Up(QWidget):
def init(self, parent=None):
super(Sign_Up, self).init(parent)
self.table = QTableWidget(0, 6)
self.table.setHorizontalHeaderLabels(['DriverID', 'Full Name', 'Age', 'Phone','Time in', 'Time out'])
self.table.setAlternatingRowColors(True)
self.table.setEditTriggers(QTableWidget.NoEditTriggers)
self.table.setSelectionBehavior(QTableWidget.SelectRows)
self.table.setSelectionMode(QTableWidget.SingleSelection)
self.lblDriverID = QLabel("DriverID:")
self.txtDriverID = QLineEdit()
self.txtDriverID.setPlaceholderText("DriverID")
self.lblFullName = QLabel("Full Name:")
self.txtFullName = QLineEdit()
self.txtFullName.setPlaceholderText("Full Name")
self.lbAge = QLabel("Age:")
self.txtAge = QLineEdit()
self.txtAge.setPlaceholderText("Age")
self.lblPhone = QLabel("Phone:")
self.txtPhone = QLineEdit()
self.txtPhone.setPlaceholderText("Phone")
self.lblTimein = QLabel("Time in:")
self.txtTimein = QLineEdit()
self.txtTimein.setPlaceholderText("Time in")
self.lblTimeout = QLabel("Time out:")
self.txtTimeout = QLineEdit()
self.txtTimeout.setPlaceholderText("Time out")
grid = QGridLayout()
grid.addWidget(self.lblDriverID, 0, 0)
grid.addWidget(self.txtDriverID, 0, 1)
grid.addWidget(self.lblFullName, 1, 0)
grid.addWidget(self.txtFullName, 1, 1)
grid.addWidget(self.lbAge, 2, 0)
grid.addWidget(self.txtAge, 2, 1)
grid.addWidget(self.lblPhone, 3,0)
grid.addWidget(self.txtPhone, 3, 1)
grid.addWidget(self.lblTimein, 4,0)
grid.addWidget(self.txtTimein, 4, 1)
grid.addWidget(self.lblTimeout, 5,0)
grid.addWidget(self.txtTimeout, 5, 1)
btnLoad = QPushButton('Load Data')
btnLoad.clicked.connect(self.loadData)
btnInsert = QPushButton('Add')
btnInsert.clicked.connect(self.insertData)
btnRemove = QPushButton('Delete')
btnRemove.clicked.connect(self.removeData)
hbx = QHBoxLayout()
hbx.addWidget(btnLoad)
hbx.addWidget(btnInsert)
hbx.addWidget(btnRemove)
vbx = QVBoxLayout()
vbx.addLayout(grid)
vbx.addLayout(hbx)
vbx.setAlignment(Qt.AlignTop)
vbx.addWidget(self.table)
self.setWindowTitle("YellowDot Transport Inc.")
self.resize(500, 500)
self.setLayout(vbx)
def loadData(self, event):
index = 0
query = QSqlQuery()
query.exec_("select * from person")
while query.next():
driverID = query.value(0)
fullname = query.value(1)
age = query.value(2)
phone = query.value(3)
time_in = query.value(4)
time_out = query.value(5)
self.table.setRowCount(index + 1)
self.table.setItem(index, 0, QTableWidgetItem(str(driverID)))
self.table.setItem(index, 1, QTableWidgetItem(fullname))
self.table.setItem(index, 2, QTableWidgetItem(age))
self.table.setItem(index, 3, QTableWidgetItem(phone))
self.table.setItem(index, 4, QTableWidgetItem(time_in))
self.table.setItem(index, 5, QTableWidgetItem(time_out))
index += 1
def insertData(self, event):
driver_ID = int(self.txtDriverID.text())
full_name = self.txtFullName.text()
age = self.txtAge.text()
phone= self.txtPhone.text()
time_in= self.txtTimeIn.text()
time_out= self.txtTimeOut.text()
query = QSqlQuery()
query.exec_("insert into person values({0}, '{1}', '{2}', '{3}','{4}','{5}')".format(driver_ID, full_name, age, phone, time_in, time_out))
def removeData(self, event):
selected = self.table.currentIndex()
if not selected.isValid() or len(self.table.selectedItems()) < 1:
return
DriverID = self.table.selectedItems()[0]
query = QSqlQuery()
query.exec_("delete from person where id = " + DriverID.text())
self.table.removeRow(selected.row())
self.table.setCurrentIndex(QModelIndex())
def db_connect(self, filename, server):
db = QSqlDatabase.addDatabase(server)
db.setDatabaseName(filename)
if not db.open():
QMessageBox.critical(None, "Cannot open database",
"Unable to establish a database connection.n"
"This example needs SQLite support. Please read the Qt SQL "
"driver documentation for information how to build it.nn"
"Click Cancel to exit.", QMessageBox.Cancel)
return False
return True
def db_fillupform(self):
query = QSqlQuery()
query.exec_("create table person(id int primary key, "
"fullname varchar(20), age varchar(20), phone varchar(11), timein varchar(10), timeout varchar(10))")
query.exec_("insert into person values(101, 'Cagnaan, John Albert B', '19', 09991835096,'7:30','4:00')")
query.exec_("insert into person values(102, 'Cepe, Vince Paul', '19', 09999150854,'7:30','4:00')")
query.exec_("insert into person values(103, 'Resquid, Macky', '19', 09999988701,'7:30','4:00')")
query.exec_("insert into person values(104, 'Resquid, Macky', '19', 09999988702,'7:30','4:00')")
query.exec_("insert into person values(105, 'Resquid, Macky', '19', 09999988703,'7:30','4:00')")
def init(self, filename, server):
import os
if not os.path.exists(filename):
self.db_connect(filename, server)
self.db_create()
else:
self.db_connect(filename, server)
if name == 'main':
app = QtWidgets.QApplication(sys.argv)
app = QApplication(sys.argv)
ejm = Sign_Up()
ejm.init('datafile', 'QSQLITE')
ejm.show()
login = Login()
python python-3.x pyqt
$endgroup$
closed as unclear what you're asking by yuri, πάντα ῥεῖ, Ludisposed, pacmaninbw, Vogel612♦ Mar 17 at 13:45
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
$begingroup$
import sys
from PyQt5 import QtWidgets
from PyQt5.QtSql import QSqlQuery, QSqlDatabase
from PyQt5.QtCore import Qt, QModelIndex
from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QPushButton, QTableWidget, QTableWidgetItem, QMessageBox, QHBoxLayout, QLineEdit, QLabel, QGridLayout
class Login(QtWidgets.QDialog):
def __init__(self, parent=None):
super(Login, self).__init__(parent)
self.textName = QtWidgets.QLineEdit(self)
self.textPass = QtWidgets.QLineEdit(self)
self.buttonLogin = QtWidgets.QPushButton('Login', self)
self.buttonLogin.clicked.connect(self.handleLogin)
layout = QtWidgets.QVBoxLayout(self)
layout.addWidget(self.textName)
layout.addWidget(self.textPass)
layout.addWidget(self.buttonLogin)
def handleLogin(self):
if (self.textName.text() == 'admin' and
self.textPass.text() == 'admin'):
self.accept()
else:
QtWidgets.QMessageBox.warning(
self, 'Error', 'Try Again')
class Sign_Up(QWidget):
def init(self, parent=None):
super(Sign_Up, self).init(parent)
self.table = QTableWidget(0, 6)
self.table.setHorizontalHeaderLabels(['DriverID', 'Full Name', 'Age', 'Phone','Time in', 'Time out'])
self.table.setAlternatingRowColors(True)
self.table.setEditTriggers(QTableWidget.NoEditTriggers)
self.table.setSelectionBehavior(QTableWidget.SelectRows)
self.table.setSelectionMode(QTableWidget.SingleSelection)
self.lblDriverID = QLabel("DriverID:")
self.txtDriverID = QLineEdit()
self.txtDriverID.setPlaceholderText("DriverID")
self.lblFullName = QLabel("Full Name:")
self.txtFullName = QLineEdit()
self.txtFullName.setPlaceholderText("Full Name")
self.lbAge = QLabel("Age:")
self.txtAge = QLineEdit()
self.txtAge.setPlaceholderText("Age")
self.lblPhone = QLabel("Phone:")
self.txtPhone = QLineEdit()
self.txtPhone.setPlaceholderText("Phone")
self.lblTimein = QLabel("Time in:")
self.txtTimein = QLineEdit()
self.txtTimein.setPlaceholderText("Time in")
self.lblTimeout = QLabel("Time out:")
self.txtTimeout = QLineEdit()
self.txtTimeout.setPlaceholderText("Time out")
grid = QGridLayout()
grid.addWidget(self.lblDriverID, 0, 0)
grid.addWidget(self.txtDriverID, 0, 1)
grid.addWidget(self.lblFullName, 1, 0)
grid.addWidget(self.txtFullName, 1, 1)
grid.addWidget(self.lbAge, 2, 0)
grid.addWidget(self.txtAge, 2, 1)
grid.addWidget(self.lblPhone, 3,0)
grid.addWidget(self.txtPhone, 3, 1)
grid.addWidget(self.lblTimein, 4,0)
grid.addWidget(self.txtTimein, 4, 1)
grid.addWidget(self.lblTimeout, 5,0)
grid.addWidget(self.txtTimeout, 5, 1)
btnLoad = QPushButton('Load Data')
btnLoad.clicked.connect(self.loadData)
btnInsert = QPushButton('Add')
btnInsert.clicked.connect(self.insertData)
btnRemove = QPushButton('Delete')
btnRemove.clicked.connect(self.removeData)
hbx = QHBoxLayout()
hbx.addWidget(btnLoad)
hbx.addWidget(btnInsert)
hbx.addWidget(btnRemove)
vbx = QVBoxLayout()
vbx.addLayout(grid)
vbx.addLayout(hbx)
vbx.setAlignment(Qt.AlignTop)
vbx.addWidget(self.table)
self.setWindowTitle("YellowDot Transport Inc.")
self.resize(500, 500)
self.setLayout(vbx)
def loadData(self, event):
index = 0
query = QSqlQuery()
query.exec_("select * from person")
while query.next():
driverID = query.value(0)
fullname = query.value(1)
age = query.value(2)
phone = query.value(3)
time_in = query.value(4)
time_out = query.value(5)
self.table.setRowCount(index + 1)
self.table.setItem(index, 0, QTableWidgetItem(str(driverID)))
self.table.setItem(index, 1, QTableWidgetItem(fullname))
self.table.setItem(index, 2, QTableWidgetItem(age))
self.table.setItem(index, 3, QTableWidgetItem(phone))
self.table.setItem(index, 4, QTableWidgetItem(time_in))
self.table.setItem(index, 5, QTableWidgetItem(time_out))
index += 1
def insertData(self, event):
driver_ID = int(self.txtDriverID.text())
full_name = self.txtFullName.text()
age = self.txtAge.text()
phone= self.txtPhone.text()
time_in= self.txtTimeIn.text()
time_out= self.txtTimeOut.text()
query = QSqlQuery()
query.exec_("insert into person values({0}, '{1}', '{2}', '{3}','{4}','{5}')".format(driver_ID, full_name, age, phone, time_in, time_out))
def removeData(self, event):
selected = self.table.currentIndex()
if not selected.isValid() or len(self.table.selectedItems()) < 1:
return
DriverID = self.table.selectedItems()[0]
query = QSqlQuery()
query.exec_("delete from person where id = " + DriverID.text())
self.table.removeRow(selected.row())
self.table.setCurrentIndex(QModelIndex())
def db_connect(self, filename, server):
db = QSqlDatabase.addDatabase(server)
db.setDatabaseName(filename)
if not db.open():
QMessageBox.critical(None, "Cannot open database",
"Unable to establish a database connection.n"
"This example needs SQLite support. Please read the Qt SQL "
"driver documentation for information how to build it.nn"
"Click Cancel to exit.", QMessageBox.Cancel)
return False
return True
def db_fillupform(self):
query = QSqlQuery()
query.exec_("create table person(id int primary key, "
"fullname varchar(20), age varchar(20), phone varchar(11), timein varchar(10), timeout varchar(10))")
query.exec_("insert into person values(101, 'Cagnaan, John Albert B', '19', 09991835096,'7:30','4:00')")
query.exec_("insert into person values(102, 'Cepe, Vince Paul', '19', 09999150854,'7:30','4:00')")
query.exec_("insert into person values(103, 'Resquid, Macky', '19', 09999988701,'7:30','4:00')")
query.exec_("insert into person values(104, 'Resquid, Macky', '19', 09999988702,'7:30','4:00')")
query.exec_("insert into person values(105, 'Resquid, Macky', '19', 09999988703,'7:30','4:00')")
def init(self, filename, server):
import os
if not os.path.exists(filename):
self.db_connect(filename, server)
self.db_create()
else:
self.db_connect(filename, server)
if name == 'main':
app = QtWidgets.QApplication(sys.argv)
app = QApplication(sys.argv)
ejm = Sign_Up()
ejm.init('datafile', 'QSQLITE')
ejm.show()
login = Login()
python python-3.x pyqt
$endgroup$
closed as unclear what you're asking by yuri, πάντα ῥεῖ, Ludisposed, pacmaninbw, Vogel612♦ Mar 17 at 13:45
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
$begingroup$
Welcome to Code Review! I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
$endgroup$
– Vogel612♦
Mar 17 at 13:45
add a comment |
$begingroup$
import sys
from PyQt5 import QtWidgets
from PyQt5.QtSql import QSqlQuery, QSqlDatabase
from PyQt5.QtCore import Qt, QModelIndex
from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QPushButton, QTableWidget, QTableWidgetItem, QMessageBox, QHBoxLayout, QLineEdit, QLabel, QGridLayout
class Login(QtWidgets.QDialog):
def __init__(self, parent=None):
super(Login, self).__init__(parent)
self.textName = QtWidgets.QLineEdit(self)
self.textPass = QtWidgets.QLineEdit(self)
self.buttonLogin = QtWidgets.QPushButton('Login', self)
self.buttonLogin.clicked.connect(self.handleLogin)
layout = QtWidgets.QVBoxLayout(self)
layout.addWidget(self.textName)
layout.addWidget(self.textPass)
layout.addWidget(self.buttonLogin)
def handleLogin(self):
if (self.textName.text() == 'admin' and
self.textPass.text() == 'admin'):
self.accept()
else:
QtWidgets.QMessageBox.warning(
self, 'Error', 'Try Again')
class Sign_Up(QWidget):
def init(self, parent=None):
super(Sign_Up, self).init(parent)
self.table = QTableWidget(0, 6)
self.table.setHorizontalHeaderLabels(['DriverID', 'Full Name', 'Age', 'Phone','Time in', 'Time out'])
self.table.setAlternatingRowColors(True)
self.table.setEditTriggers(QTableWidget.NoEditTriggers)
self.table.setSelectionBehavior(QTableWidget.SelectRows)
self.table.setSelectionMode(QTableWidget.SingleSelection)
self.lblDriverID = QLabel("DriverID:")
self.txtDriverID = QLineEdit()
self.txtDriverID.setPlaceholderText("DriverID")
self.lblFullName = QLabel("Full Name:")
self.txtFullName = QLineEdit()
self.txtFullName.setPlaceholderText("Full Name")
self.lbAge = QLabel("Age:")
self.txtAge = QLineEdit()
self.txtAge.setPlaceholderText("Age")
self.lblPhone = QLabel("Phone:")
self.txtPhone = QLineEdit()
self.txtPhone.setPlaceholderText("Phone")
self.lblTimein = QLabel("Time in:")
self.txtTimein = QLineEdit()
self.txtTimein.setPlaceholderText("Time in")
self.lblTimeout = QLabel("Time out:")
self.txtTimeout = QLineEdit()
self.txtTimeout.setPlaceholderText("Time out")
grid = QGridLayout()
grid.addWidget(self.lblDriverID, 0, 0)
grid.addWidget(self.txtDriverID, 0, 1)
grid.addWidget(self.lblFullName, 1, 0)
grid.addWidget(self.txtFullName, 1, 1)
grid.addWidget(self.lbAge, 2, 0)
grid.addWidget(self.txtAge, 2, 1)
grid.addWidget(self.lblPhone, 3,0)
grid.addWidget(self.txtPhone, 3, 1)
grid.addWidget(self.lblTimein, 4,0)
grid.addWidget(self.txtTimein, 4, 1)
grid.addWidget(self.lblTimeout, 5,0)
grid.addWidget(self.txtTimeout, 5, 1)
btnLoad = QPushButton('Load Data')
btnLoad.clicked.connect(self.loadData)
btnInsert = QPushButton('Add')
btnInsert.clicked.connect(self.insertData)
btnRemove = QPushButton('Delete')
btnRemove.clicked.connect(self.removeData)
hbx = QHBoxLayout()
hbx.addWidget(btnLoad)
hbx.addWidget(btnInsert)
hbx.addWidget(btnRemove)
vbx = QVBoxLayout()
vbx.addLayout(grid)
vbx.addLayout(hbx)
vbx.setAlignment(Qt.AlignTop)
vbx.addWidget(self.table)
self.setWindowTitle("YellowDot Transport Inc.")
self.resize(500, 500)
self.setLayout(vbx)
def loadData(self, event):
index = 0
query = QSqlQuery()
query.exec_("select * from person")
while query.next():
driverID = query.value(0)
fullname = query.value(1)
age = query.value(2)
phone = query.value(3)
time_in = query.value(4)
time_out = query.value(5)
self.table.setRowCount(index + 1)
self.table.setItem(index, 0, QTableWidgetItem(str(driverID)))
self.table.setItem(index, 1, QTableWidgetItem(fullname))
self.table.setItem(index, 2, QTableWidgetItem(age))
self.table.setItem(index, 3, QTableWidgetItem(phone))
self.table.setItem(index, 4, QTableWidgetItem(time_in))
self.table.setItem(index, 5, QTableWidgetItem(time_out))
index += 1
def insertData(self, event):
driver_ID = int(self.txtDriverID.text())
full_name = self.txtFullName.text()
age = self.txtAge.text()
phone= self.txtPhone.text()
time_in= self.txtTimeIn.text()
time_out= self.txtTimeOut.text()
query = QSqlQuery()
query.exec_("insert into person values({0}, '{1}', '{2}', '{3}','{4}','{5}')".format(driver_ID, full_name, age, phone, time_in, time_out))
def removeData(self, event):
selected = self.table.currentIndex()
if not selected.isValid() or len(self.table.selectedItems()) < 1:
return
DriverID = self.table.selectedItems()[0]
query = QSqlQuery()
query.exec_("delete from person where id = " + DriverID.text())
self.table.removeRow(selected.row())
self.table.setCurrentIndex(QModelIndex())
def db_connect(self, filename, server):
db = QSqlDatabase.addDatabase(server)
db.setDatabaseName(filename)
if not db.open():
QMessageBox.critical(None, "Cannot open database",
"Unable to establish a database connection.n"
"This example needs SQLite support. Please read the Qt SQL "
"driver documentation for information how to build it.nn"
"Click Cancel to exit.", QMessageBox.Cancel)
return False
return True
def db_fillupform(self):
query = QSqlQuery()
query.exec_("create table person(id int primary key, "
"fullname varchar(20), age varchar(20), phone varchar(11), timein varchar(10), timeout varchar(10))")
query.exec_("insert into person values(101, 'Cagnaan, John Albert B', '19', 09991835096,'7:30','4:00')")
query.exec_("insert into person values(102, 'Cepe, Vince Paul', '19', 09999150854,'7:30','4:00')")
query.exec_("insert into person values(103, 'Resquid, Macky', '19', 09999988701,'7:30','4:00')")
query.exec_("insert into person values(104, 'Resquid, Macky', '19', 09999988702,'7:30','4:00')")
query.exec_("insert into person values(105, 'Resquid, Macky', '19', 09999988703,'7:30','4:00')")
def init(self, filename, server):
import os
if not os.path.exists(filename):
self.db_connect(filename, server)
self.db_create()
else:
self.db_connect(filename, server)
if name == 'main':
app = QtWidgets.QApplication(sys.argv)
app = QApplication(sys.argv)
ejm = Sign_Up()
ejm.init('datafile', 'QSQLITE')
ejm.show()
login = Login()
python python-3.x pyqt
$endgroup$
import sys
from PyQt5 import QtWidgets
from PyQt5.QtSql import QSqlQuery, QSqlDatabase
from PyQt5.QtCore import Qt, QModelIndex
from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QPushButton, QTableWidget, QTableWidgetItem, QMessageBox, QHBoxLayout, QLineEdit, QLabel, QGridLayout
class Login(QtWidgets.QDialog):
def __init__(self, parent=None):
super(Login, self).__init__(parent)
self.textName = QtWidgets.QLineEdit(self)
self.textPass = QtWidgets.QLineEdit(self)
self.buttonLogin = QtWidgets.QPushButton('Login', self)
self.buttonLogin.clicked.connect(self.handleLogin)
layout = QtWidgets.QVBoxLayout(self)
layout.addWidget(self.textName)
layout.addWidget(self.textPass)
layout.addWidget(self.buttonLogin)
def handleLogin(self):
if (self.textName.text() == 'admin' and
self.textPass.text() == 'admin'):
self.accept()
else:
QtWidgets.QMessageBox.warning(
self, 'Error', 'Try Again')
class Sign_Up(QWidget):
def init(self, parent=None):
super(Sign_Up, self).init(parent)
self.table = QTableWidget(0, 6)
self.table.setHorizontalHeaderLabels(['DriverID', 'Full Name', 'Age', 'Phone','Time in', 'Time out'])
self.table.setAlternatingRowColors(True)
self.table.setEditTriggers(QTableWidget.NoEditTriggers)
self.table.setSelectionBehavior(QTableWidget.SelectRows)
self.table.setSelectionMode(QTableWidget.SingleSelection)
self.lblDriverID = QLabel("DriverID:")
self.txtDriverID = QLineEdit()
self.txtDriverID.setPlaceholderText("DriverID")
self.lblFullName = QLabel("Full Name:")
self.txtFullName = QLineEdit()
self.txtFullName.setPlaceholderText("Full Name")
self.lbAge = QLabel("Age:")
self.txtAge = QLineEdit()
self.txtAge.setPlaceholderText("Age")
self.lblPhone = QLabel("Phone:")
self.txtPhone = QLineEdit()
self.txtPhone.setPlaceholderText("Phone")
self.lblTimein = QLabel("Time in:")
self.txtTimein = QLineEdit()
self.txtTimein.setPlaceholderText("Time in")
self.lblTimeout = QLabel("Time out:")
self.txtTimeout = QLineEdit()
self.txtTimeout.setPlaceholderText("Time out")
grid = QGridLayout()
grid.addWidget(self.lblDriverID, 0, 0)
grid.addWidget(self.txtDriverID, 0, 1)
grid.addWidget(self.lblFullName, 1, 0)
grid.addWidget(self.txtFullName, 1, 1)
grid.addWidget(self.lbAge, 2, 0)
grid.addWidget(self.txtAge, 2, 1)
grid.addWidget(self.lblPhone, 3,0)
grid.addWidget(self.txtPhone, 3, 1)
grid.addWidget(self.lblTimein, 4,0)
grid.addWidget(self.txtTimein, 4, 1)
grid.addWidget(self.lblTimeout, 5,0)
grid.addWidget(self.txtTimeout, 5, 1)
btnLoad = QPushButton('Load Data')
btnLoad.clicked.connect(self.loadData)
btnInsert = QPushButton('Add')
btnInsert.clicked.connect(self.insertData)
btnRemove = QPushButton('Delete')
btnRemove.clicked.connect(self.removeData)
hbx = QHBoxLayout()
hbx.addWidget(btnLoad)
hbx.addWidget(btnInsert)
hbx.addWidget(btnRemove)
vbx = QVBoxLayout()
vbx.addLayout(grid)
vbx.addLayout(hbx)
vbx.setAlignment(Qt.AlignTop)
vbx.addWidget(self.table)
self.setWindowTitle("YellowDot Transport Inc.")
self.resize(500, 500)
self.setLayout(vbx)
def loadData(self, event):
index = 0
query = QSqlQuery()
query.exec_("select * from person")
while query.next():
driverID = query.value(0)
fullname = query.value(1)
age = query.value(2)
phone = query.value(3)
time_in = query.value(4)
time_out = query.value(5)
self.table.setRowCount(index + 1)
self.table.setItem(index, 0, QTableWidgetItem(str(driverID)))
self.table.setItem(index, 1, QTableWidgetItem(fullname))
self.table.setItem(index, 2, QTableWidgetItem(age))
self.table.setItem(index, 3, QTableWidgetItem(phone))
self.table.setItem(index, 4, QTableWidgetItem(time_in))
self.table.setItem(index, 5, QTableWidgetItem(time_out))
index += 1
def insertData(self, event):
driver_ID = int(self.txtDriverID.text())
full_name = self.txtFullName.text()
age = self.txtAge.text()
phone= self.txtPhone.text()
time_in= self.txtTimeIn.text()
time_out= self.txtTimeOut.text()
query = QSqlQuery()
query.exec_("insert into person values({0}, '{1}', '{2}', '{3}','{4}','{5}')".format(driver_ID, full_name, age, phone, time_in, time_out))
def removeData(self, event):
selected = self.table.currentIndex()
if not selected.isValid() or len(self.table.selectedItems()) < 1:
return
DriverID = self.table.selectedItems()[0]
query = QSqlQuery()
query.exec_("delete from person where id = " + DriverID.text())
self.table.removeRow(selected.row())
self.table.setCurrentIndex(QModelIndex())
def db_connect(self, filename, server):
db = QSqlDatabase.addDatabase(server)
db.setDatabaseName(filename)
if not db.open():
QMessageBox.critical(None, "Cannot open database",
"Unable to establish a database connection.n"
"This example needs SQLite support. Please read the Qt SQL "
"driver documentation for information how to build it.nn"
"Click Cancel to exit.", QMessageBox.Cancel)
return False
return True
def db_fillupform(self):
query = QSqlQuery()
query.exec_("create table person(id int primary key, "
"fullname varchar(20), age varchar(20), phone varchar(11), timein varchar(10), timeout varchar(10))")
query.exec_("insert into person values(101, 'Cagnaan, John Albert B', '19', 09991835096,'7:30','4:00')")
query.exec_("insert into person values(102, 'Cepe, Vince Paul', '19', 09999150854,'7:30','4:00')")
query.exec_("insert into person values(103, 'Resquid, Macky', '19', 09999988701,'7:30','4:00')")
query.exec_("insert into person values(104, 'Resquid, Macky', '19', 09999988702,'7:30','4:00')")
query.exec_("insert into person values(105, 'Resquid, Macky', '19', 09999988703,'7:30','4:00')")
def init(self, filename, server):
import os
if not os.path.exists(filename):
self.db_connect(filename, server)
self.db_create()
else:
self.db_connect(filename, server)
if name == 'main':
app = QtWidgets.QApplication(sys.argv)
app = QApplication(sys.argv)
ejm = Sign_Up()
ejm.init('datafile', 'QSQLITE')
ejm.show()
login = Login()
python python-3.x pyqt
python python-3.x pyqt
asked Mar 17 at 7:04
user195400user195400
1
1
closed as unclear what you're asking by yuri, πάντα ῥεῖ, Ludisposed, pacmaninbw, Vogel612♦ Mar 17 at 13:45
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by yuri, πάντα ῥεῖ, Ludisposed, pacmaninbw, Vogel612♦ Mar 17 at 13:45
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
$begingroup$
Welcome to Code Review! I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
$endgroup$
– Vogel612♦
Mar 17 at 13:45
add a comment |
$begingroup$
Welcome to Code Review! I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
$endgroup$
– Vogel612♦
Mar 17 at 13:45
$begingroup$
Welcome to Code Review! I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
$endgroup$
– Vogel612♦
Mar 17 at 13:45
$begingroup$
Welcome to Code Review! I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
$endgroup$
– Vogel612♦
Mar 17 at 13:45
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Welcome to Code Review! I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information.
$endgroup$
– Vogel612♦
Mar 17 at 13:45