Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Set text doesnt set text...
Forum Updated to NodeBB v4.3 + New Features

Set text doesnt set text...

Scheduled Pinned Locked Moved Unsolved Qt for Python
3 Posts 2 Posters 343 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Samuel Bachorik
    wrote on last edited by
    #1

    Hello guys, please i already made similar topic but in this one iam using classes and iam facing same problem... This code just dont work and i have NO idea why. Function setExpresion in main.py is executed but doesnt set text...

    File main.py

    from PyQt5 import QtWidgets
    import sys
    from PyQt5.QtWidgets import QMainWindow, QApplication, QLineEdit
    
    class Window(QMainWindow):
       def __init__(self):
           super().__init__()
           self.textboxvalue2 = ""
           self.setWindowTitle("Samuel")
           self.setGeometry(200, 200, 259, 258)
    
           self.textbox = QLineEdit(self)
           self.textbox.move(5, 5)
           self.textbox.resize(188, 35)
           self.textbox.setText(str(self.textboxvalue2))
           self.textbox.setPlaceholderText("Enter numbers")
           self.textboxValue = self.textbox.text()
    
           self.b10 = QtWidgets.QPushButton(self)
           self.b10.setText("0")
           self.b10.move(68, 219)
           self.b10.resize(60, 35)
           self.b10.clicked.connect(self.clicked0)
           self.show()
    
       def setExpression(self,expression):
           print(expression) 
           self.textbox.setText(str(expression))
    
       def clicked0(self):
           import Buttons
           z = Buttons.Buttons()
           z.buttonOne()
    
    if __name__ == "__main__":
        app = QApplication(sys.argv)
        window = Window()
        sys.exit(app.exec())
    

    File Buttons.py

    class Buttons:
    
        def buttonOne(self):
            import main
            x = main.Window()
            x.setExpression("1")
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Same as before, you are creating a local variable that is short lived and has nothing to do with the instance you create in your main.py file.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • S Offline
        S Offline
        Samuel Bachorik
        wrote on last edited by
        #3

        Thank you now it is working !!!!!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved