I am trying to update a counter variable inside my GUI that is constantly changing. From my source code, at line 50, "NothingFound_Counter" and "Total" are global variables from another function dynamically changing. I want the GUI to also reflect this but the way I have it so far is only displaying the initialized static value at 0.
I have two dilemmas I am trying to solve here
Update the global variables so that the GUI will also refresh the value when the value of this variable changes
I want to take the inputs of the buttons from this GUI function as the inputs to my other function. What is the proper syntax to do this?
import sys
import os
import fut
import PyQt5
import random
from PyQt5 import QtWidgets, QtCore
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class GuiWindow(QWidget):
def __init__(self, parent = None):
super(GuiWindow, self).__init__(parent)
global Found_Counter
global NothingFound_Counter
#self.setFixedWidth(300)
#self.setFixedHeight(150)
self.resize(300,150)
layout = QFormLayout()
self.btn = QPushButton("Style")
self.btn.clicked.connect(self.getItem)
self.le = QLineEdit()
layout.addRow(self.btn,self.le)
self.btn1 = QPushButton("Name")
self.btn1.clicked.connect(self.gettext)
self.le1 = QLineEdit()
layout.addRow(self.btn1,self.le1)
self.btn2 = QPushButton("Max Buy Now")
self.btn2.clicked.connect(self.getint)
self.le2 = QLineEdit()
layout.addRow(self.btn2,self.le2)
self.setLayout(layout)
self.setWindowTitle("clicker :D")
self.run = QPushButton('RUN', self)
self.run.clicked.connect(self.clickMethod)
self.run.resize(100,32)
self.run.move(150,100)
self.counter1 = QtWidgets.QLabel('',self)
layout = QtWidgets.QHBoxLayout(self)
layout.addWidget(self.counter1, alignment=QtCore.Qt.AlignBottom)
self.counter1.move(50,100)
self.counter1.setText(f'Items Found is {fut.NothingFound_Counter} / {fut.Total}')
def getItem(self):
items = ("test1", "test2", "test3" )
item, ok = QInputDialog.getItem(self, "select input dialog",
"list of styles", items, 0, False)
if ok and item:
self.le.setText(item)
def gettext(self):
text, ok = QInputDialog.getText(self, 'Text Input Dialog', 'Enter the name:')
if ok:
self.le1.setText(str(text))
def getint(self):
num,ok = QInputDialog.getInt(self,"integer input dualog","enter a number")
if ok:
self.le2.setText(str(num))
def clickMethod(self):
fut.Main()
def main():
app = QApplication(sys.argv)
ex = GuiWindow()
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
simplified fut function is as such:
import os
import csv
import pip._vendor.requests
import pyautogui
import time
import PIL
from PIL import Image
import urllib.request
import re
import random
import sys
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow
import gui
Found_Counter = 0
NothingFound_Counter = 0
Total = 0
def NoResultsFound():
global Found_Counter
global NothingFound_Counter
NoResultsLocation = pyautogui.locateOnScreen('NoResultsFound2.png', region = (1205, 846, 500, 160))
time.sleep(2)
if NoResultsLocation == None:
Found_Counter = Found_Counter + 1
else:
NothingFound_Counter = NothingFound_Counter + 1
Total = Found_Counter + NothingFound_Counter
print(f'NothingFound_Count = {NothingFound_Counter}')
print(f'Found_Count = {Found_Counter}')
print(f'Total = {Total}')
def Main():
while True:
time.sleep(random.randrange(1,5))
#goTransfer()
for x in range (10):
NoResultsFound()
time.sleep(random.randrange(1,5))
clearTransfer()
time.sleep(random.randrange(1,5))