import mysql connector import npyscreen class App npyscreen StandardAp

 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
import mysql.connector
import npyscreen
class App(npyscreen.StandardApp):
def onStart(self):
self.addForm("MAIN", MainForm, name = "Программа работает с базой данных")
class MainForm(npyscreen.ActionFormMinimal):
def create(self):
self.grid = self.add(npyscreen.GridColTitles)
self.grid.values= []
mydb = mysql.connector.connect(host="127.0.0.1",
port ="3311",
user="root",
password="root",
charset='utf8',
database = "mydb")
query = "SELECT title_eng, title_rus, year FROM film"
mycursor = mydb.cursor()
mycursor.execute(query)
for row in mycursor:
grid_row = []
for cell in row:
grid_row.append(cell)
self.grid.values.append(grid_row)
def on_ok(self):
self.parentApp.setNextForm(None)
my_app = App()
my_app.run()