Request for future: give us a specific subject e.g. how do I restore a
button's text/color ?
On 3/18/2020 6:05 PM, mjnash...@gmail.com wrote:
Absolute beginner here, have no idea what I am doing wrong. All I want to do here is have
the pushButton in PyQt5 to change to "Working..." and Red when clicked... which
it currently does.
That's amazing since your code sets the text to WORKING...
Thing is I need it to also change back to the default "SCAN" and Green color
when done running that method the button is linked to...
I know this is a super simple problem, and forgive any Novice errors in this
code. I know very very little but if you guys can help me I would highly
appreciate it!!! :)
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
import pyautogui
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.showMaximized()
MainWindow.setMinimumSize(QtCore.QSize(0, 0))
MainWindow.setMaximumSize(QtCore.QSize(3840, 2160))
font = QtGui.QFont()
font.setFamily("Arial Black")
MainWindow.setFont(font)
MainWindow.setStyleSheet("background-color: rgba(0, 85, 127, 100);")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(250, 250, 400, 150))
font = QtGui.QFont()
font.setFamily("Tahoma")
font.setPointSize(24)
font.setBold(True)
font.setWeight(75)
self.pushButton.setFont(font)
self.pushButton.setStyleSheet("background-color: rgb(0, 170, 0);\n"
"color: rgb(255, 255, 255);")
self.pushButton.setObjectName("pushButton")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(730, 300, 701, 111))
font = QtGui.QFont()
font.setPointSize(18)
font.setBold(True)
font.setItalic(False)
font.setWeight(75)
self.label.setFont(font)
self.label.setLayoutDirection(QtCore.Qt.LeftToRight)
self.label.setObjectName("label")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1920, 18))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.label.setStyleSheet("background-color: rgba(0, 85, 127, 0);\n"
"color: rgb(255, 255, 255);")
self.pushButton.setText(_translate("MainWindow", "SCAN"))
self.label.setText(_translate("MainWindow", "WELCOME"))
self.pushButton.clicked.connect(self.copy)
When user clicks button self.copy is invoked. True?
def copy(self, MainWindow):
self.pushButton.setText('WORKING...')
Why do you sometimes use _translate and not other times?
self.pushButton.setStyleSheet("background-color: rgb(250, 0, 0);\n"
"color: rgb(255, 255, 255);")
testprompt=storeid=pyautogui.prompt(text='test', title='test')
This method does no actual work! If you add
self.pushButton.setText(_translate("MainWindow", "SCAN"))
self.pushButton.setStyleSheet # whatever it was originally
it will reset the button. Of course it will so really fast, as there is
no actual work being done.
So you should first address the issue of actually doing something that
will take a little time. Also it is not a good idea to duplicate code,
so I would put those 2 lines in a function and call that function from 2
places.
Am I going in the right direction? Am I missing something?
class Application():
def run():
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
Application.run()
Bob Gailer
--
https://mail.python.org/mailman/listinfo/python-list