Найти - Пользователи
Полная версия: Помощь с pyqt5.Как сделать так, чтобы при повторном нажатие на pyshbButton сбрасывался/изменялся/обнулялся результат и наоборот. Помогите пожалуйста
Начало » Python для новичков » Помощь с pyqt5.Как сделать так, чтобы при повторном нажатие на pyshbButton сбрасывался/изменялся/обнулялся результат и наоборот. Помогите пожалуйста
1
miha2002
from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName(“Dialog”)
Dialog.resize(612, 534)
Dialog.setStyleSheet(“ background-color:rgb(75, 75, 75)”)
self.verticalLayoutWidget = QtWidgets.QWidget(Dialog)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(200, 180, 231, 83))
self.verticalLayoutWidget.setObjectName(“verticalLayoutWidget”)
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName(“verticalLayout”)
self.pushButton_3 = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.pushButton_3.setStyleSheet(“ background-color:rgb(0, 255, 38)”)
self.pushButton_3.setObjectName(“pushButton_3”)
self.verticalLayout.addWidget(self.pushButton_3)
self.pushButton_2 = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.pushButton_2.setObjectName(“pushButton_2”)
self.verticalLayout.addWidget(self.pushButton_2)
self.pushButton = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.pushButton.setStyleSheet(“ background-color:rgb(170, 3, 3)”)
self.pushButton.setObjectName(“pushButton”)
self.verticalLayout.addWidget(self.pushButton)
self.pushButton_4 = QtWidgets.QPushButton(Dialog)
self.pushButton_4.setGeometry(QtCore.QRect(200, 152, 231, 31))
self.pushButton_4.setStyleSheet(“ background-color:rgb(38, 173, 233)”)
self.pushButton_4.setObjectName(“pushButton_4”)
self.lineEdit = QtWidgets.QLineEdit(Dialog)
self.lineEdit.setGeometry(QtCore.QRect(200, 90, 121, 61))
self.lineEdit.setReadOnly(True)
self.lineEdit.setObjectName(“lineEdit”)
self.lineEdit_2 = QtWidgets.QLineEdit(Dialog)
self.lineEdit_2.setGeometry(QtCore.QRect(320, 90, 111, 61))
self.lineEdit_2.setDragEnabled(True)
self.lineEdit_2.setReadOnly(True)
self.lineEdit_2.setObjectName(“lineEdit_2”)
self.lineEdit_3 = QtWidgets.QLineEdit(Dialog)
self.lineEdit_3.setGeometry(QtCore.QRect(200, 260, 231, 31))
self.lineEdit_3.setDragEnabled(True)
self.lineEdit_3.setReadOnly(True)
self.lineEdit_3.setObjectName(“lineEdit_3”)

self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)

def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate(“Dialog”, “Dialog”))
self.pushButton_3.setText(_translate(“Dialog”, “Больше”))
self.pushButton_2.setText(_translate(“Dialog”, “Равно”))
self.pushButton.setText(_translate(“Dialog”, “Меньше”))
self.pushButton_4.setToolTip(_translate(“Dialog”, “<html><head/><body><p align=\”center\“><span style=\” font-size:14pt;\“>Начать</span></p></body></html>”))
self.pushButton_4.setText(_translate(“Dialog”, “Начать”))
self.lineEdit_3.setText(_translate(“Dialog”, “Результат: ”))


if __name__ == “__main__”:
import sys
import random
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
aba = random.randint(0,100)
cdf = random.randint(0,100)


Dialog.show()
def pb():
ui.lineEdit.setText( str(aba) )
ui.pushButton_4.clicked.connect( pb )

def g():

ui.lineEdit_2.setText( str(cdf) )
if aba > cdf:
ui.lineEdit_3.setText( “Поражение”)
elif aba < cdf:
ui.lineEdit_3.setText( “Победа”)

ui.pushButton_3.clicked.connect( g )





def k():
ui.lineEdit_2.setText( str(cdf) )
if aba > cdf:
ui.lineEdit_3.setText( “Победа” )
elif aba < cdf:
ui.lineEdit_3.setText( “Поражение” )
ui.pushButton.clicked.connect( k )


ui.pushButton.clicked.connect( k )
def p ():
ui.lineEdit_2.setText( str(cdf) )
if aba == cdf:
ui.lineEdit_3.setText( “Победа” )
elif:
ui.lineEdit_3.setText( “Поражение” )

ui.pushButton_2.clicked.connect ( p )








sys.exit(app.exec_())
PEHDOM
miha2002 поместите код в теги
 [code python][/code]
и что значит “ и наоборот”?
miha2002
PEHDOM
miha2002 поместите код в теги
пример:
нажимаю на кнопку(pushbutton) и мне выводит в llineEdit рандомное число
при повторном нажатие вводит другое число.
PEHDOM
miha2002
пример:
нажимаю на кнопку(pushbutton) и мне выводит в llineEdit рандомное число
при повторном нажатие вводит другое число.


 from PyQt5 import QtWidgets
import sys
import random
def btn_press():
    lineEdit.setText(str(random.randint(0, 100)))
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
verticalLayout = QtWidgets.QVBoxLayout(Dialog)
pushButton = QtWidgets.QPushButton('press me',Dialog)
pushButton.clicked.connect(btn_press)
verticalLayout.addWidget(pushButton)
lineEdit = QtWidgets.QLineEdit(Dialog)
lineEdit.setReadOnly(True)
verticalLayout.addWidget(lineEdit)
Dialog.show()
sys.exit(app.exec_())
miha2002
PEHDOM
Спасибо!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB