-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistaluno.py
81 lines (60 loc) · 2.66 KB
/
listaluno.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Form implementation generated from reading ui file 'listaluno.ui'
#
# Created by: PyQt6 UI code generator 6.5.0
#
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt6 import QtCore, QtGui, QtWidgets
# Conexão com o BD
import mysql.connector
conexao = mysql.connector.connect(
host="localhost", user="root",
password="", database="escola")
cursor = conexao.cursor()
print("Conectado ao BD.")
class Ui_ListaAluno(object):
def setupUi(self, ListaAluno):
ListaAluno.setObjectName("ListaAluno")
ListaAluno.resize(309, 244)
self.centralwidget = QtWidgets.QWidget(parent=ListaAluno)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.botao_listar = QtWidgets.QPushButton(parent=self.centralwidget)
self.botao_listar.setObjectName("botao_listar")
self.botao_listar.clicked.connect(self.listar)
self.verticalLayout.addWidget(self.botao_listar)
self.text_dados = QtWidgets.QTextEdit(parent=self.centralwidget)
self.text_dados.setObjectName("text_dados")
self.text_dados.setReadOnly(True)
self.verticalLayout.addWidget(self.text_dados)
ListaAluno.setCentralWidget(self.centralwidget)
self.retranslateUi(ListaAluno)
QtCore.QMetaObject.connectSlotsByName(ListaAluno)
def retranslateUi(self, ListaAluno):
_translate = QtCore.QCoreApplication.translate
ListaAluno.setWindowTitle(_translate("ListaAluno", "Listagem de Alunos"))
self.botao_listar.setText(_translate("ListaAluno", "Listar"))
def listar(self):
sql = "SELECT * FROM ALUNO"
cursor.execute(sql)
dados = cursor.fetchall()
texto = ""
for linha in dados:
texto += "Código: " + str(linha[0]) + "\n"
texto += "Nome: " + linha[1] + "\n"
texto += "Curso: " + linha[2] + "\n"
texto += "Turno: " + linha[3] + "\n"
texto += "Atleta: " + linha[4] + "\n"
texto += "Bolsista: " + linha[5] + "\n"
texto += "Obs: " + linha[6] + "\n"
texto += "==============================\n"
self.text_dados.setPlainText(texto)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
ListaAluno = QtWidgets.QMainWindow()
ui = Ui_ListaAluno()
ui.setupUi(ListaAluno)
ListaAluno.show()
sys.exit(app.exec())