Try to search your question here, if you can't find : Ask Any Question Now ?

how can i set the text of the QLabel in pyqt5 to variable?

HomeCategory: stackoverflowhow can i set the text of the QLabel in pyqt5 to variable?
kundan asked 1 week ago

i have two windows, main window that opens the second window where i want to have the Qlabel set to a variable called average_waiting.

The problem is that i want average_waiting to be global because it will be changed throughout the code ,

so this results in closing the whole program when i attempt to open the second window from the main window

Part of the code :

class MainWindow(QMainWindow):
def __init__(self,parent=None):
    super().__init__(parent)
    self.setWindowTitle("My Program")
    #self.setWindowIcon(QtGui.QIcon("download.jpg"))
    self.setGeometry(50,50,500,300)
    self.home()
    self.show()

def home(self):


    self.label2=QLabel(self)
    self.label2.setText("Type of Scheduler")
    self.label2.move(10,50)

    self.textbox2=QLineEdit(self)
    self.textbox2.move(100,50)


    self.button=QPushButton("Go",self)
    self.button.move(0,200)
    self.button.clicked.connect(self.runcode)

def runcode(self):
  schedular_type=self.textbox2.text()
  if(schedular_type=="FCFS"):
   self.close()
   self.fcfs=Window2(self,0)





//second window



 class Window2(QMainWindow):

def __init__(self,parent=None,average_waiting=0):
    super().__init__(parent)
    self.setWindowTitle("FCFS")
    #self.setWindowIcon(QtGui.QIcon("download.jpg"))
    self.setGeometry(50,50,500,300)
    self.average_waiting=average_waiting
    self.home()
    self.show()

def home(self):
    self.label1=QLabel(self)
    self.label1.setText("No of Processes")
    self.label1.move(10,0) #col ,row

    self.textbox=QLineEdit(self)
    self.textbox.move(100,0)


    self.label3=QLabel(self)
    self.label3.setText("Processess Names")
    self.label3.move(10,50)

    self.label4=QLabel(self)
    self.label4.setText("Burst Time")
    self.label4.move(10,100)

    self.label5=QLabel(self)
    self.label5.setText("Arrival Time")
    self.label5.move(10,150)

    self.names=QLineEdit(self)
    self.names.move(100,50)
    self.names.resize(1400,30)

    self.burst=QLineEdit(self)
    self.burst.move(100,100)
    self.burst.resize(1400,30)

    self.arrival=QLineEdit(self)
    self.arrival.move(100 ,150)
    self.arrival.resize(1400,30)
    #self.textEdit=QTextEdit(self)
    #self.textEdit.move(20,250)
    self.label6=QLabel(self)
    self.label6.setText("Waiting Time=",self.average_waiting)
    self.label6.move(0,250)
1 Answers
Best Answer
Amit answered 1 week ago
Your Answer

10 + 19 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com