Unsolved showing a value in the GUI
-
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? -
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.
-
@Denni-0 done :)
-
@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. -
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