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. showing a value in the GUI
Forum Updated to NodeBB v4.3 + New Features

showing a value in the GUI

Scheduled Pinned Locked Moved Unsolved Qt for Python
5 Posts 3 Posters 875 Views
  • 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.
  • immmommI Offline
    immmommI Offline
    immmomm
    wrote on last edited by
    #1

    hi guys!
    i made an GUI and try to show a number that is updating irregular.
    I use
    self.label_show_cash.setText(str(balance()))
    but the value is not changing in the GUI.
    any idea?

    cheese

    JonBJ 1 Reply Last reply
    0
    • immmommI Offline
      immmommI Offline
      immmomm
      wrote on last edited by
      #2

      okay so I have this function in another .py file:

      
      def balance():
      	balfunc = list(con.get_accounts().get('balance'))
      	bal = str((balfunc[0]))
      	print(bal)
      	return(bal)
      
      

      the output of this is: 49970.07

      the output can change.

      and this is the main file for the GUI

      import sys
      from PyQt5 import QtWidgets, QtGui, QtCore
      from multiprocessing import freeze_support
      
      
      from odin.data.basic import balance
      
      # Import main page ui file
      from odin.gui.main_window import Ui_MainWindow
      
      # Import dialog page ui file
      #from odin.gui import dialogue_page
      
      
      class MainWindow_exec(QtWidgets.QMainWindow, Ui_MainWindow):
          def __init__(self, parent=None):
              QtWidgets.QMainWindow.__init__(self, parent)
              self.setupUi(self)
      
              # Functions in the main_window
              self.pushButton_quit.clicked.connect(self.close)
              self.label_show_cash.setText(str(balance()))
      
      
      if __name__ == '__main__':
          # This line help avoid errors related to multiprocessing when freezing the application.
          freeze_support()
      
          # Start application
          app = QtWidgets.QApplication(sys.argv)
          app.setQuitOnLastWindowClosed(False)
      
          # Set application style. Styles: WindowsVista,Windows,Fusion
          # s = QtWidgets.QStyleFactory.create('Fusion')
          # app.setStyle(s)
      
          # Set application id and icon for taskbar
          myappid = 'odin'  # arbitrary string
      
          app_icon = QtGui.QIcon()
          app_icon.addFile('basic_logo.png', QtCore.QSize(16, 16))
          app_icon.addFile('basic_logo.png', QtCore.QSize(24, 24))
          app_icon.addFile('basic_logo.png', QtCore.QSize(32, 32))
          app_icon.addFile('basic_logo.png', QtCore.QSize(48, 48))
          app_icon.addFile('basic_logo.png', QtCore.QSize(256, 256))
          app.setWindowIcon(app_icon)
      
          # Call mainwindow and start eventloop
          MainWindow1 = MainWindow_exec()
          MainWindow1.show()
          sys.exit(app.exec_())
      

      i want to see the value at the balance label I made.

      cheese

      1 Reply Last reply
      0
      • immmommI Offline
        immmommI Offline
        immmomm
        wrote on last edited by
        #3

        @Denni-0 done :)

        cheese

        1 Reply Last reply
        0
        • immmommI immmomm

          hi guys!
          i made an GUI and try to show a number that is updating irregular.
          I use
          self.label_show_cash.setText(str(balance()))
          but the value is not changing in the GUI.
          any idea?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @immmomm said in showing a value in the GUI:

          but the value is not changing in the GUI.

          Do you understand that you need to hook onto an "event" which arrives when the value changes, and update the label in response to that? In Qt you need to write a slot in your code and connect it to a signal which arrives when the value has, or might have, changed. The signal might be a dedicated one which is emitted when the balance changes, or it might be for a QTimer which is ticking away and calls for update periodically.

          1 Reply Last reply
          0
          • immmommI Offline
            immmommI Offline
            immmomm
            wrote on last edited by
            #5

            thank you all!!

            so the ui-designer is for "nothing"?
            I use it because i can change the design fast without loosing the code for the action for buttons

            cheese

            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