我正在使用 pyqt GUI 应用程序在 postgres 数据库的图表中显示一些结果,但它不起作用
这是我使用的代码
这就是我创建表格的方式
create_table_transaction = ''' CREATE TABLE IF NOT EXISTS transactions (
id SERIAL PRIMARY KEY UNIQUE NOT NULL,
montant DECIMAL(100,2),
medecin VARCHAR,
date_d DATE,
time_d TIME,
users_id INTEGER,
FOREIGN KEY(users_id) REFERENCES users(id)) '''
这是在 Qchart 小部件中绘制图表的功能
from PyQt5 import *
from PyQt5 import QtCore, QtGui, QtWidgets, QtPrintSupport
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import Qt
from PyQt5.QtSql import *
from PyQt5.QtPrintSupport import QPrintDialog, QPrinter, QPrintPreviewDialog
import sys, sqlite3
import psycopg2
import datetime
from datetime import timedelta
from PyQt5.QtCore import QDate
import sys
from PyQt5.QtChart import QChart, QLineSeries
from PyQt5.QtChart import *
from PyQt5.uic import loadUiType
from admin import Ui_MainWindow as ui
class MainApp(QMainWindow, ui):
def __init__(self):
QMainWindow.__init__(self)
self.setupUi(self)
self.Handel_Buttons()
def Handel_Buttons(self):
self.pushButton_113.clicked.connect(self.draw_chart01)
def draw_chart01(self): #pushButton_113
self.connection = psycopg2.connect(user="postgres",
password="password",
host="localhost",
database="database")
self.cur = self.connection.cursor()
date = str(self.dateEdit_19.text())
self.cur.execute( '''SELECT medecin, montant FROM transactions WHERE date_d = %s ''',(date,))
rows = self.cur.fetchall()
rightseries = QPieSeries()
for entry in rows:
print(entry)
rightseries.append(entry[0], entry[1])
LEATH
相关分类