Я понимаю что тема очень заезженная, НО если есть возможность помогите - не могу понять почему при нажатии кнопок не обновляются данные окна. Кто может прочитать мой код и подсказать где ошибка Программа берет данные и вставляет их в QLabel мой код
from PyQt5 import QtGui
from PyQt5.QtWidgets import QApplication, QDialog, QPushButton, QMessageBox
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
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
class Winop(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
db = MySQLdb.connect("", "", "", "")
# QMessageBox.about(self, 'Connection', 'Database Connected Successfully')
self.kolstrok = 1
cursor = db.cursor()
cursor.execute("select count(*) from list_device")
self.kolnew = cursor.fetchone()[0]
self.Bazaset()
def Bazaset(self):
ip = 0
self.Winset()
# db------------------------------------------------------------------------------------
try:
db = MySQLdb.connect("", "", "", "")
cursor = db.cursor()
cursor.execute("select device_id, ip from list_device WHERE device_id=" +str(self.kolstrok))
for row_ip in cursor.fetchall():
ip = row_ip[1]
cursor.execute("select * from _data_in_memory WHERE device_id=" +str(self.kolstrok))
self.label.lab = QtWidgets.QLabel(self)
font = QtGui.QFont()
font.setFamily("Times New Roman")
self.setFont(font)
font.setPointSize(10)
self.label.lab.setFont(font)
self.label.lab.setGeometry(QtCore.QRect(10, 20, 295, 20))
self.label.lab.setText("Ip " + ip)
print(ip)
for row_dan in cursor.fetchall():
self.label.lab1 = QtWidgets.QLabel(self)
self.label.lab1.setGeometry(QtCore.QRect(10, 40, 140, 20))
self.label.lab1.setText("internal temperature В°C")
self.label.lab11 = QtWidgets.QLabel(self)
self.label.lab11.setGeometry(QtCore.QRect(160, 40, 100, 20))
self.label.lab11.setText(row_dan[2])
db.close()
except MySQLdb.Error as e:
QMessageBox.about(self, 'Connection', 'Failed To Connect Database')
sys.exit(1)
# db --------------------------------------------------------------------------------
def Winset(self):
self.window_height = 300
self.window_width = 500
self.setObjectName("menu")
font = QtGui.QFont()
font.setFamily("Times New Roman")
self.setFont(font)
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
self.setFixedSize(self.window_height, self.window_width)
self.setWindowIcon(QIcon('logo1.png'))
self.setWindowTitle("Teco monitoring")
oImage = QImage("6706.jpg")
sImage = oImage.scaled(QSize(self.window_height, self.window_width))
palette = QPalette()
palette.setBrush(QPalette.Window, QBrush(sImage))
self.setPalette(palette)
self.label = QtWidgets.QLabel(self)
self.label.setFont(font)
self.label.setGeometry(QtCore.QRect(100, 5, 101, 20))
self.label.setText("Current values")
self.previous = QtWidgets.QPushButton(self)
self.previous.setGeometry(QtCore.QRect(20, 450, 70, 23))
self.previous.setFont(font)
self.previous.setObjectName("Previous")
self.previous.clicked.connect(self.minus)
self.previous.setText("Previous")
self.next = QtWidgets.QPushButton(self)
self.next.setGeometry(QtCore.QRect(200, 450, 70, 23))
self.next.setFont(font)
self.next.setObjectName("Next")
self.next.clicked.connect(self.plus)
self.next.setText("Next")
def plus(self):
self.kolstrok = self.kolstrok + 1
if (self.kolstrok > self.kolnew):
self.kolstrok = 1
else:
self.kolstrok = 2
self.Bazaset()
def minus(self):
self.kolstrok = self.kolstrok - 1
if (self.kolstrok == 0):
self.kolstrok = 1
self.Bazaset()
# END ------------------------------------------------------------------------
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
F2_window = Winop()
F2_window.show()
sys.exit(app.exec_())