Issue
my ui main window contains:
self.clickcount = 0
This is my button press:
def nextApplicant(self):
self.clickcount += 1
print(self.clickcount)
self.label_4.setText(clickcount)
so print(self.clickcount) prints no problem but I can't use it for anything else. It wont appear in my label. I can't send it to a text document. What's going on here?
from __future__ import print_function
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QSize
from PyQt5.QtCore import QStringListModel
from PyQt5.QtCore import Qt, QFile, QFileInfo, QTextStream
from PyQt5.QtGui import QColor, QPalette
from PyQt5.QtWidgets import QBoxLayout
from PyQt5.QtWidgets import QMainWindow, QPushButton, QWidget, QComboBox, QLabel, QLineEdit, QApplication, QGridLayout, \
QCompleter, QFormLayout, QStackedLayout
from PyQt5.QtWidgets import qApp
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QColor, QPalette
from datetime import date, timedelta
from datetime import datetime, date
from pandas.tseries.frequencies import to_offset
from shutil import copy2
import cv2
import configparser
import ctypes
import errno
import getpass
import glob
import json
import os
import pandas as pd
import pathlib
import pdfrw
import re
import requests
import shutil
import subprocess
import sys
import time
import unittest
import webbrowser
import pyautogui
import threading
import sys
import time
import threading
import socket
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(552, 285)
MainWindow.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
MainWindow.setWindowOpacity(0.8)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(440, 170, 81, 23))
self.pushButton.setObjectName("pushButton")
self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_5.setGeometry(QtCore.QRect(20, 170, 81, 23))
self.pushButton_5.setObjectName("pushButton_5")
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
self.textEdit.setGeometry(QtCore.QRect(20, 20, 501, 131))
self.textEdit.setObjectName("textEdit")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(150, 160, 221, 21))
self.label_4.setObjectName("label_4")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(440, 210, 81, 23))
self.pushButton_2.setObjectName("pushButton_2")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.clickcount = 0
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.pushButton_5.clicked.connect(self.nextApplicant)
self.textEdit.setFontPointSize(14)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "sdfsdf"))
self.pushButton.setText(_translate("MainWindow", "N/A"))
self.pushButton_5.setText(_translate("MainWindow", "NEXT"))
self.label_4.setText(_translate("MainWindow", "test"))
self.pushButton_2.setText(_translate("MainWindow", "MERGE"))
def nextApplicant(self):
self.clickcount += 1
print(self.clickcount)
self.label_4.setText(self.clickcount)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
app.setStyle('Fusion')
palette = QtGui.QPalette()
palette.setColor(QtGui.QPalette.Window, QColor(27, 35, 38))
palette.setColor(QtGui.QPalette.WindowText, QColor(234, 234, 234))
palette.setColor(QtGui.QPalette.Base, QColor(42, 50, 53))
palette.setColor(QtGui.QPalette.AlternateBase, QColor(12, 15, 16))
palette.setColor(QtGui.QPalette.ToolTipBase, QColor(27, 35, 38))
palette.setColor(QtGui.QPalette.ToolTipText, Qt.white)
palette.setColor(QtGui.QPalette.Text, QColor(234, 234, 234))
palette.setColor(QtGui.QPalette.Button, QColor(27, 35, 38))
palette.setColor(QtGui.QPalette.ButtonText, Qt.white)
palette.setColor(QtGui.QPalette.BrightText, QColor(100, 215, 222))
palette.setColor(QtGui.QPalette.Link, QColor(126, 71, 130))
palette.setColor(QtGui.QPalette.HighlightedText, Qt.white)
palette.setColor(QtGui.QPalette.Disabled, QPalette.Light, Qt.black)
palette.setColor(QtGui.QPalette.Disabled, QPalette.Shadow, QColor(12, 15, 16))
MainWindow.setPalette(palette)
sys.exit(app.exec_())
Solution
If you just want to assign the value of the self.clickcount
variable to the self.label_4
label, you need to convert the value of self.clickcount
to a string since the setText method takes a string as an argument.
def nextApplicant(self):
self.clickcount += 1
print(self.clickcount)
self.label_4.setText(str(self.clickcount))
Answered By - Lenta
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.