Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 037c44d

Browse files
Create Desktop Application with Table - Python PyQT6
Create Desktop Application with Table - Python PyQT6
1 parent c7cda17 commit 037c44d

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

‎initdb.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import sqlite3
2+
connection = sqlite3.connect("projects.db")
3+
cursor = connection.cursor()
4+
cursor.execute("""
5+
CREATE TABLE projects
6+
(url TEXT, descr TEXT, income INTEGER)
7+
""")
8+
cursor.execute("""INSERT INTO projects VALUES
9+
('giraffes.io', 'Uber, but with giraffes', 1900),
10+
('dronesweaters.com', 'Clothes for cold drones', 3000),
11+
('hummingpro.io', 'Online humming courses', 120000)
12+
""")
13+
14+
#for row in cursor.execute("SELECT * FROM projects"):
15+
# print(row)
16+
17+
18+
connection.commit()

‎main.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from os.path import exists
2+
from PyQt6.QtWidgets import *
3+
from PyQt6.QtSql import *
4+
5+
import sys
6+
7+
if not exists("projects.db"):
8+
print("File projects.db does not exist. Please run initdb.py.")
9+
sys.exit()
10+
11+
app = QApplication([])
12+
db = QSqlDatabase.addDatabase("QSQLITE")
13+
db.setDatabaseName("projects.db")
14+
db.open()
15+
model = QSqlTableModel(None, db)
16+
model.setTable("projects")
17+
model.select()
18+
view = QTableView()
19+
view.setModel(model)
20+
view.show()
21+
app.exec()

‎projects.db

8 KB
Binary file not shown.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /