没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
python3+PyQt5使用数据库窗口视图使用数据库窗口视图
主要为大家详细介绍了python3+PyQt5使用数据库窗口视图,具有一定的参考价值,感兴趣的小伙伴们可以参考
一下
能够为数据库数据提供的最简单的用户界面之一就是窗体,窗体可以一次性呈现出来自同一记录的各个域。本文通过
python3+pyqt5改写实现了python Qt gui 快速变成15章的例子。
#!/usr/bin/env python3
import os
import sys
from PyQt5.QtCore import (QDate, QDateTime, QFile, QVariant, Qt)
from PyQt5.QtWidgets import (QApplication, QDataWidgetMapper,QComboBox,
QDateTimeEdit, QDialog, QGridLayout, QHBoxLayout, QLabel,
QLineEdit, QMessageBox, QPushButton, QVBoxLayout)
from PyQt5.QtGui import QIcon,QPixmap,QCursor
from PyQt5.QtSql import (QSqlDatabase, QSqlQuery, QSqlRelation,
QSqlRelationalDelegate, QSqlRelationalTableModel)
import qrc_resources
MAC = True
try:
from PyQt5.QtGui import qt_mac_set_native_menubar
except ImportError:
MAC = False
ID, CALLER, STARTTIME, ENDTIME, TOPIC, OUTCOMEID = range(6)
DATETIME_FORMAT = "yyyy-MM-dd hh:mm"
def createFakeData():
import random
print("Dropping tables...")
query = QSqlQuery()
query.exec_("DROP TABLE calls")
query.exec_("DROP TABLE outcomes")
QApplication.processEvents()
print("Creating tables...")
query.exec_("""CREATE TABLE outcomes (
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL,
name VARCHAR(40) NOT NULL)""")
query.exec_("""CREATE TABLE calls (
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL,
caller VARCHAR(40) NOT NULL,
starttime DATETIME NOT NULL,
endtime DATETIME NOT NULL,
topic VARCHAR(80) NOT NULL,
outcomeid INTEGER NOT NULL,
FOREIGN KEY (outcomeid) REFERENCES outcomes)""")
QApplication.processEvents()
print("Populating tables...")
for name in ("Resolved", "Unresolved", "Calling back", "Escalate",
"Wrong number"):
query.exec_("INSERT INTO outcomes (name) VALUES ('{0}')".format(
name))
topics = ("Complaint", "Information request", "Off topic",
"Information supplied", "Complaint", "Complaint")
now = QDateTime.currentDateTime()
query.prepare("INSERT INTO calls (caller, starttime, endtime, "
"topic, outcomeid) VALUES (:caller, :starttime, "
":endtime, :topic, :outcomeid)")
for name in ('Joshan Cockerall', 'Ammanie Ingham',
'Diarmuid Bettington', 'Juliana Bannister',
'Oakley-Jay Buxton', 'Reilley Collinge',
'Ellis-James Mcgehee', 'Jazmin Lawton',
'Lily-Grace Smythe', 'Coskun Lant', 'Lauran Lanham',
'Millar Poindexter', 'Naqeeb Neild', 'Maxlee Stoddart',
'Rebia Luscombe', 'Briana Christine', 'Charli Pease',
'Deena Mais', 'Havia Huffman', 'Ethan Davie',
'Thomas-Jack Silver', 'Harpret Bray', 'Leigh-Ann Goodliff',
'Seoras Bayes', 'Jenna Underhill', 'Veena Helps',
'Mahad Mcintosh', 'Allie Hazlehurst', 'Aoife Warrington',
'Cameron Burton', 'Yildirim Ahlberg', 'Alissa Clayton',
'Josephine Weber', 'Fiore Govan', 'Howard Ragsdale',
资源评论
weixin_38570202
- 粉丝: 9
- 资源: 952
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功