Вот мой пример на таблице - блин что я делаю не так
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
import time
from PyQt5 import QtCore
from PyQt5.QtCore import *
from PyQt5.QtWidgets import QApplication, QTableView
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import pymysql.cursors
import pymysql
pymysql.install_as_MySQLdb()
import MySQLdb
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QApplication, QDialog, QDialogButtonBox,
QHBoxLayout, QMessageBox, QPushButton, QTableView)
from PyQt5.QtSql import QSqlTableModel
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QTableView
from PyQt5.QtSql import QSqlTableModel
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
class Widget(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.starw()
def starw(self):
self.window_height = 300
self.window_width = 600
self.setFixedSize(self.window_height, self.window_width)
self.setWindowIcon(QIcon('logo1.png'))
self.setWindowTitle("Teco monitoring")
layout = QtWidgets.QVBoxLayout(self)
btn_layout = QtWidgets.QHBoxLayout()
btn1 = QtWidgets.QPushButton("Previous")
btn2 = QtWidgets.QPushButton("Quit")
btn3 = QtWidgets.QPushButton("Next")
btn_layout.addWidget(btn1)
btn_layout.addWidget(btn2)
btn_layout.addWidget(btn3)
btn1.clicked.connect(self.minus)
btn2.clicked.connect(QCoreApplication.instance().quit)
btn3.clicked.connect(self.plus)
table = QtWidgets.QTableWidget()
table.setRowCount(6)
table.setColumnCount(2)
table.setHorizontalHeaderLabels(["Mark", "Devise"])
table.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
layout.addWidget(table)
layout.addLayout(btn_layout)
self.baza(table)
def baza(self, table):
self.kolstrok = 1
db = MySQLdb.connect("", "", "", "")
# print("connect DB successful!!")
cursor = db.cursor()
cursor.execute("select * from _data_in_memory WHERE device_id=" + str(self.kolstrok))
for dan in cursor.fetchall():
print(self.kolstrok)
table.setItem(0, 0, QTableWidgetItem("IP"))
table.setItem(0, 1, QTableWidgetItem(str(dan[0])))
table.setItem(1, 0, QTableWidgetItem("Titul"))
table.setItem(1, 1, QTableWidgetItem(str(self.kolstrok)))
table.setItem(2, 0, QTableWidgetItem("Model"))
table.setItem(2, 1, QTableWidgetItem(dan[2]))
table.setItem(3, 0, QTableWidgetItem("Mame"))
table.setItem(3, 1, QTableWidgetItem(dan[3]))
table.setItem(4, 0, QTableWidgetItem("Regoin"))
table.setItem(4, 1, QTableWidgetItem(dan[4]))
table.setItem(5, 0, QTableWidgetItem("Adres"))
table.setItem(5, 1, QTableWidgetItem(dan[5]))
def plus(self):
self.kolstrok = str(self.kolstrok + 1)
if (self.kolstrok > self.kolnew):
self.kolstrok = 1
else:
self.kolstrok = 2
print(self.kolstrok)
self.baza()
def minus(self):
self.kolstrok = str(self.kolstrok - 1)
if (self.kolstrok == 0):
self.kolstrok = 1
print(self.kolstrok)
self.baza()
if __name__ == '__main__':
app = QtWidgets.QApplication([])
w = Widget()
w.show()
app.exec()