QLCDNumber Class - Наследует: QFrame.
QFrame Class - Наследует: QWidget.
Нет необходимости каждый раз создавать - self.network = QLabel (self)
.
Вам не нужноglobal
переменных.
Попробуйте:
import sys
import os
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
#time2 = ""
class DigitalClock(QLCDNumber): #, QWidget):
def __init__(self, parent=None):
super(DigitalClock, self).__init__(parent)
self.time2 = True # +
self.network = QLabel(self) # +
self.network.setGeometry(50, 300, 150, 150) # +
self.setWindowTitle("Digital Clock")
self.showFullScreen()
self.mainlayout = QHBoxLayout() # ?
timer = QTimer(self)
timer.timeout.connect(self.ui)
self.ui()
timer.start(1000)
def ui(self):
# global time2 # ---
time = QTime.currentTime()
text = time.toString('hh:mm')
if (time.second() % 2) == 0:
text = text[:2]+" "+ text[3:]
# if text[3:] != time2:
# if os.system("ping -c 1 192.168.63.145") == 0:
if self.time2:
# self.network = QLabel(self) # ---
self.network.setPixmap(QPixmap("im.png").scaled(150, 150, Qt.KeepAspectRatio, Qt.FastTransformation))
# time2 = text[3:]
else:
# self.network = QLabel(self)
self.network.setPixmap(QPixmap("Ok.png").scaled(150, 150, Qt.KeepAspectRatio, Qt.FastTransformation))
# time2 = text[3:]
self.time2 = not self.time2
self.display(text)
def main():
app = QApplication(sys.argv)
clock = DigitalClock()
clock.show() # +
sys.exit(app.exec_())
if __name__ == '__main__':
main()
![enter image description here](https://i.stack.imgur.com/eeznA.png)