使用 Pyqt5 为按钮添加功能
Adding function to button Using Pyqt5
我是 QT 设计器和 PYQT5 的新手,我在向我在 GUI 上创建的“添加到购物车”按钮添加功能时遇到问题。该按钮假设从下拉框中获取样式、名称、颜色和项目的大小,并将其显示在下面的控制台日志中。
from PyQt5 import QtCore, QtGui, QtWidgets
from selenium import webdriver
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(927, 701)
MainWindow.setStyleSheet("background-color: rgb(255, 255, 255);")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox.setGeometry(QtCore.QRect(40, 20, 341, 391))
self.groupBox.setStyleSheet("background-color: rgb(255, 255, 255);")
self.groupBox.setObjectName("groupBox")
self.label = QtWidgets.QLabel(self.groupBox)
self.label.setGeometry(QtCore.QRect(10, 30, 46, 41))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.groupBox)
self.label_2.setGeometry(QtCore.QRect(10, 70, 46, 41))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.groupBox)
self.label_3.setGeometry(QtCore.QRect(10, 140, 46, 41))
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(self.groupBox)
self.label_4.setGeometry(QtCore.QRect(10, 180, 46, 41))
self.label_4.setObjectName("label_4")
self.label_5 = QtWidgets.QLabel(self.groupBox)
self.label_5.setGeometry(QtCore.QRect(10, 230, 31, 21))
self.label_5.setObjectName("label_5")
self.label_6 = QtWidgets.QLabel(self.groupBox)
self.label_6.setGeometry(QtCore.QRect(10, 300, 46, 41))
self.label_6.setObjectName("label_6")
self.label_7 = QtWidgets.QLabel(self.groupBox)
self.label_7.setGeometry(QtCore.QRect(10, 260, 46, 41))
self.label_7.setObjectName("label_7")
self.label_8 = QtWidgets.QLabel(self.groupBox)
self.label_8.setGeometry(QtCore.QRect(10, 340, 46, 41))
self.label_8.setObjectName("label_8")
self.lineEdit = QtWidgets.QLineEdit(self.groupBox)
self.lineEdit.setGeometry(QtCore.QRect(60, 40, 113, 20))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(self.groupBox)
self.lineEdit_2.setGeometry(QtCore.QRect(60, 80, 113, 20))
self.lineEdit_2.setObjectName("lineEdit_2")
self.lineEdit_3 = QtWidgets.QLineEdit(self.groupBox)
self.lineEdit_3.setGeometry(QtCore.QRect(60, 110, 113, 20))
self.lineEdit_3.setObjectName("lineEdit_3")
self.lineEdit_4 = QtWidgets.QLineEdit(self.groupBox)
self.lineEdit_4.setGeometry(QtCore.QRect(60, 150, 113, 20))
self.lineEdit_4.setObjectName("lineEdit_4")
self.lineEdit_5 = QtWidgets.QLineEdit(self.groupBox)
self.lineEdit_5.setGeometry(QtCore.QRect(60, 190, 113, 20))
self.lineEdit_5.setObjectName("lineEdit_5")
self.lineEdit_6 = QtWidgets.QLineEdit(self.groupBox)
self.lineEdit_6.setGeometry(QtCore.QRect(60, 230, 51, 20))
self.lineEdit_6.setObjectName("lineEdit_6")
self.lineEdit_7 = QtWidgets.QLineEdit(self.groupBox)
self.lineEdit_7.setGeometry(QtCore.QRect(60, 270, 113, 20))
self.lineEdit_7.setObjectName("lineEdit_7")
self.comboBox = QtWidgets.QComboBox(self.groupBox)
self.comboBox.setGeometry(QtCore.QRect(60, 310, 51, 22))
self.comboBox.setObjectName("comboBox")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox_2 = QtWidgets.QComboBox(self.groupBox)
self.comboBox_2.setGeometry(QtCore.QRect(60, 350, 69, 22))
self.comboBox_2.setObjectName("comboBox_2")
self.comboBox_2.addItem("")
self.groupBox_2 = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox_2.setGeometry(QtCore.QRect(40, 420, 341, 211))
self.groupBox_2.setStyleSheet("background-color: rgb(255, 255, 255);")
self.groupBox_2.setObjectName("groupBox_2")
self.label_9 = QtWidgets.QLabel(self.groupBox_2)
self.label_9.setGeometry(QtCore.QRect(10, 30, 46, 13))
self.label_9.setObjectName("label_9")
self.label_10 = QtWidgets.QLabel(self.groupBox_2)
self.label_10.setGeometry(QtCore.QRect(10, 70, 46, 13))
self.label_10.setObjectName("label_10")
self.label_11 = QtWidgets.QLabel(self.groupBox_2)
self.label_11.setGeometry(QtCore.QRect(10, 110, 46, 13))
self.label_11.setObjectName("label_11")
self.label_12 = QtWidgets.QLabel(self.groupBox_2)
self.label_12.setGeometry(QtCore.QRect(10, 140, 41, 21))
self.label_12.setObjectName("label_12")
self.comboBox_3 = QtWidgets.QComboBox(self.groupBox_2)
self.comboBox_3.setGeometry(QtCore.QRect(70, 30, 81, 22))
self.comboBox_3.setObjectName("comboBox_3")
self.comboBox_3.addItem("")
self.comboBox_3.addItem("")
self.comboBox_3.addItem("")
self.lineEdit_8 = QtWidgets.QLineEdit(self.groupBox_2)
self.lineEdit_8.setGeometry(QtCore.QRect(70, 70, 131, 20))
self.lineEdit_8.setObjectName("lineEdit_8")
self.comboBox_4 = QtWidgets.QComboBox(self.groupBox_2)
self.comboBox_4.setGeometry(QtCore.QRect(70, 110, 41, 22))
self.comboBox_4.setObjectName("comboBox_4")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_5 = QtWidgets.QComboBox(self.groupBox_2)
self.comboBox_5.setGeometry(QtCore.QRect(130, 110, 61, 22))
self.comboBox_5.setObjectName("comboBox_5")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.lineEdit_9 = QtWidgets.QLineEdit(self.groupBox_2)
self.lineEdit_9.setGeometry(QtCore.QRect(70, 150, 51, 21))
self.lineEdit_9.setObjectName("lineEdit_9")
self.groupBox_3 = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox_3.setGeometry(QtCore.QRect(390, 20, 391, 261))
self.groupBox_3.setStyleSheet("background-color: rgb(255, 255, 255);")
self.groupBox_3.setObjectName("groupBox_3")
self.comboBox_6 = QtWidgets.QComboBox(self.groupBox_3)
self.comboBox_6.setGeometry(QtCore.QRect(100, 30, 121, 22))
self.comboBox_6.setObjectName("comboBox_6")
self.comboBox_6.addItem("")
self.comboBox_6.addItem("")
self.comboBox_6.addItem("")
self.comboBox_6.addItem("")
self.comboBox_6.addItem("")
self.comboBox_6.addItem("")
self.comboBox_6.addItem("")
self.comboBox_6.addItem("")
self.comboBox_6.addItem("")
self.comboBox_6.addItem("")
self.label_13 = QtWidgets.QLabel(self.groupBox_3)
self.label_13.setGeometry(QtCore.QRect(40, 20, 46, 41))
self.label_13.setObjectName("label_13")
self.label_14 = QtWidgets.QLabel(self.groupBox_3)
self.label_14.setGeometry(QtCore.QRect(40, 60, 46, 41))
self.label_14.setObjectName("label_14")
self.label_15 = QtWidgets.QLabel(self.groupBox_3)
self.label_15.setGeometry(QtCore.QRect(40, 150, 46, 41))
self.label_15.setObjectName("label_15")
self.label_16 = QtWidgets.QLabel(self.groupBox_3)
self.label_16.setGeometry(QtCore.QRect(40, 100, 51, 41))
self.label_16.setObjectName("label_16")
self.comboBox_7 = QtWidgets.QComboBox(self.groupBox_3)
self.comboBox_7.setGeometry(QtCore.QRect(100, 160, 81, 22))
self.comboBox_7.setObjectName("comboBox_7")
self.comboBox_7.addItem("")
self.comboBox_7.addItem("")
self.comboBox_7.addItem("")
self.comboBox_7.addItem("")
self.comboBox_7.addItem("")
self.comboBox_7.addItem("")
self.comboBox_7.addItem("")
self.comboBox_7.addItem("")
self.lineEdit_10 = QtWidgets.QLineEdit(self.groupBox_3)
self.lineEdit_10.setGeometry(QtCore.QRect(100, 70, 121, 20))
self.lineEdit_10.setObjectName("lineEdit_10")
self.lineEdit_11 = QtWidgets.QLineEdit(self.groupBox_3)
self.lineEdit_11.setGeometry(QtCore.QRect(100, 110, 121, 20))
self.lineEdit_11.setObjectName("lineEdit_11")
self.Addtocart = QtWidgets.QPushButton(self.groupBox_3)
self.Addtocart.setGeometry(QtCore.QRect(120, 210, 141, 23))
self.Addtocart.setObjectName("Addtocart")
self.groupBox_4 = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox_4.setGeometry(QtCore.QRect(390, 300, 401, 241))
self.groupBox_4.setObjectName("groupBox_4")
self.plainTextEdit = QtWidgets.QPlainTextEdit(self.groupBox_4)
self.plainTextEdit.setGeometry(QtCore.QRect(10, 20, 381, 211))
self.plainTextEdit.setObjectName("plainTextEdit")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(450, 572, 111, 41))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(610, 570, 111, 41))
self.pushButton_2.setObjectName("pushButton_2")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 927, 21))
self.menubar.setObjectName("menubar")
self.menuMenu = QtWidgets.QMenu(self.menubar)
self.menuMenu.setObjectName("menuMenu")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionInstructions = QtWidgets.QAction(MainWindow)
self.actionInstructions.setObjectName("actionInstructions")
self.menuMenu.addSeparator()
self.menuMenu.addAction(self.actionInstructions)
self.menubar.addAction(self.menuMenu.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.groupBox.setTitle(_translate("MainWindow", "Billing Shipping"))
self.label.setText(_translate("MainWindow", "Name"))
self.label_2.setText(_translate("MainWindow", "Address"))
self.label_3.setText(_translate("MainWindow", "Email"))
self.label_4.setText(_translate("MainWindow", "Tel"))
self.label_5.setText(_translate("MainWindow", "Zip"))
self.label_6.setText(_translate("MainWindow", "State"))
self.label_7.setText(_translate("MainWindow", "City"))
self.label_8.setText(_translate("MainWindow", "Country"))
self.comboBox.setItemText(0, _translate("MainWindow", "AL"))
self.comboBox.setItemText(1, _translate("MainWindow", "AK"))
self.comboBox.setItemText(2, _translate("MainWindow", "AS"))
self.comboBox.setItemText(3, _translate("MainWindow", "AZ"))
self.comboBox.setItemText(4, _translate("MainWindow", "AR"))
self.comboBox.setItemText(5, _translate("MainWindow", "CA"))
self.comboBox.setItemText(6, _translate("MainWindow", "CO"))
self.comboBox.setItemText(7, _translate("MainWindow", "CT"))
self.comboBox.setItemText(8, _translate("MainWindow", "DE"))
self.comboBox.setItemText(9, _translate("MainWindow", "DC"))
self.comboBox.setItemText(10, _translate("MainWindow", "FM"))
self.comboBox.setItemText(11, _translate("MainWindow", "FL"))
self.comboBox.setItemText(12, _translate("MainWindow", "GA"))
self.comboBox.setItemText(13, _translate("MainWindow", "GU"))
self.comboBox.setItemText(14, _translate("MainWindow", "HI"))
self.comboBox.setItemText(15, _translate("MainWindow", "ID"))
self.comboBox.setItemText(16, _translate("MainWindow", "IL"))
self.comboBox.setItemText(17, _translate("MainWindow", "IN"))
self.comboBox.setItemText(18, _translate("MainWindow", "IA"))
self.comboBox.setItemText(19, _translate("MainWindow", "KS"))
self.comboBox.setItemText(20, _translate("MainWindow", "KY"))
self.comboBox.setItemText(21, _translate("MainWindow", "LA"))
self.comboBox.setItemText(22, _translate("MainWindow", "ME"))
self.comboBox.setItemText(23, _translate("MainWindow", "MH"))
self.comboBox.setItemText(24, _translate("MainWindow", "MD"))
self.comboBox.setItemText(25, _translate("MainWindow", "MA"))
self.comboBox.setItemText(26, _translate("MainWindow", "MI"))
self.comboBox.setItemText(27, _translate("MainWindow", "MN"))
self.comboBox.setItemText(28, _translate("MainWindow", "MS"))
self.comboBox.setItemText(29, _translate("MainWindow", "MO"))
self.comboBox.setItemText(30, _translate("MainWindow", "MT"))
self.comboBox.setItemText(31, _translate("MainWindow", "NE"))
self.comboBox.setItemText(32, _translate("MainWindow", "NV"))
self.comboBox.setItemText(33, _translate("MainWindow", "NH"))
self.comboBox.setItemText(34, _translate("MainWindow", "NJ"))
self.comboBox.setItemText(35, _translate("MainWindow", "NM"))
self.comboBox.setItemText(36, _translate("MainWindow", "NY"))
self.comboBox.setItemText(37, _translate("MainWindow", "NC"))
self.comboBox.setItemText(38, _translate("MainWindow", "ND"))
self.comboBox.setItemText(39, _translate("MainWindow", "MP"))
self.comboBox.setItemText(40, _translate("MainWindow", "OH"))
self.comboBox.setItemText(41, _translate("MainWindow", "OK"))
self.comboBox.setItemText(42, _translate("MainWindow", "OR"))
self.comboBox.setItemText(43, _translate("MainWindow", "PW"))
self.comboBox.setItemText(44, _translate("MainWindow", "PA"))
self.comboBox.setItemText(45, _translate("MainWindow", "PR"))
self.comboBox.setItemText(46, _translate("MainWindow", "RI"))
self.comboBox.setItemText(47, _translate("MainWindow", "SC"))
self.comboBox.setItemText(48, _translate("MainWindow", "SD"))
self.comboBox.setItemText(49, _translate("MainWindow", "TN"))
self.comboBox.setItemText(50, _translate("MainWindow", "TX"))
self.comboBox.setItemText(51, _translate("MainWindow", "UT"))
self.comboBox.setItemText(52, _translate("MainWindow", "VT"))
self.comboBox.setItemText(53, _translate("MainWindow", "VI"))
self.comboBox.setItemText(54, _translate("MainWindow", "VA"))
self.comboBox.setItemText(55, _translate("MainWindow", "WA"))
self.comboBox.setItemText(56, _translate("MainWindow", "WV"))
self.comboBox.setItemText(57, _translate("MainWindow", "WI"))
self.comboBox.setItemText(58, _translate("MainWindow", "WY"))
self.comboBox_2.setItemText(0, _translate("MainWindow", "USA"))
self.groupBox_2.setTitle(_translate("MainWindow", "Payment Info"))
self.label_9.setText(_translate("MainWindow", "Type"))
self.label_10.setText(_translate("MainWindow", "Number"))
self.label_11.setText(_translate("MainWindow", "Exp Date"))
self.label_12.setText(_translate("MainWindow", "CCV"))
self.comboBox_3.setItemText(0, _translate("MainWindow", "Visa"))
self.comboBox_3.setItemText(1, _translate("MainWindow", "American Express"))
self.comboBox_3.setItemText(2, _translate("MainWindow", "Master Card"))
self.comboBox_4.setItemText(0, _translate("MainWindow", "01"))
self.comboBox_4.setItemText(1, _translate("MainWindow", "02"))
self.comboBox_4.setItemText(2, _translate("MainWindow", "03"))
self.comboBox_4.setItemText(3, _translate("MainWindow", "04"))
self.comboBox_4.setItemText(4, _translate("MainWindow", "05"))
self.comboBox_4.setItemText(5, _translate("MainWindow", "06"))
self.comboBox_4.setItemText(6, _translate("MainWindow", "07"))
self.comboBox_4.setItemText(7, _translate("MainWindow", "08"))
self.comboBox_4.setItemText(8, _translate("MainWindow", "09"))
self.comboBox_4.setItemText(9, _translate("MainWindow", "10"))
self.comboBox_4.setItemText(10, _translate("MainWindow", "11"))
self.comboBox_4.setItemText(11, _translate("MainWindow", "12"))
self.comboBox_5.setItemText(0, _translate("MainWindow", "2017"))
self.comboBox_5.setItemText(1, _translate("MainWindow", "2018"))
self.comboBox_5.setItemText(2, _translate("MainWindow", "2019"))
self.comboBox_5.setItemText(3, _translate("MainWindow", "2020"))
self.comboBox_5.setItemText(4, _translate("MainWindow", "2021"))
self.comboBox_5.setItemText(5, _translate("MainWindow", "2022"))
self.comboBox_5.setItemText(6, _translate("MainWindow", "2023"))
self.comboBox_5.setItemText(7, _translate("MainWindow", "2024"))
self.comboBox_5.setItemText(8, _translate("MainWindow", "2025"))
self.comboBox_5.setItemText(9, _translate("MainWindow", "2026"))
self.comboBox_5.setItemText(10, _translate("MainWindow", "2027"))
self.groupBox_3.setTitle(_translate("MainWindow", "Item Finder"))
self.comboBox_6.setItemText(0, _translate("MainWindow", "Jackets"))
self.comboBox_6.setItemText(1, _translate("MainWindow", "Shirts"))
self.comboBox_6.setItemText(2, _translate("MainWindow", "Tops/Sweaters"))
self.comboBox_6.setItemText(3, _translate("MainWindow", "Sweatshirts"))
self.comboBox_6.setItemText(4, _translate("MainWindow", "Pants"))
self.comboBox_6.setItemText(5, _translate("MainWindow", "Shorts"))
self.comboBox_6.setItemText(6, _translate("MainWindow", "Hats"))
self.comboBox_6.setItemText(7, _translate("MainWindow", "accessories"))
self.comboBox_6.setItemText(8, _translate("MainWindow", "Shoes"))
self.comboBox_6.setItemText(9, _translate("MainWindow", "Skate"))
self.label_13.setText(_translate("MainWindow", "Style"))
self.label_14.setText(_translate("MainWindow", "Name"))
self.label_15.setText(_translate("MainWindow", "Size"))
self.label_16.setText(_translate("MainWindow", "Color"))
self.comboBox_7.setItemText(0, _translate("MainWindow", "Small"))
self.comboBox_7.setItemText(1, _translate("MainWindow", "Medium"))
self.comboBox_7.setItemText(2, _translate("MainWindow", "Large"))
self.comboBox_7.setItemText(3, _translate("MainWindow", "30"))
self.comboBox_7.setItemText(4, _translate("MainWindow", "31"))
self.comboBox_7.setItemText(5, _translate("MainWindow", "32"))
self.comboBox_7.setItemText(6, _translate("MainWindow", "33"))
self.comboBox_7.setItemText(7, _translate("MainWindow", "34"))
self.Addtocart.setText(_translate("MainWindow", "Add to Cart"))
self.groupBox_4.setTitle(_translate("MainWindow", "Status"))
self.pushButton.setText(_translate("MainWindow", "START"))
self.pushButton_2.setText(_translate("MainWindow", "STOP"))
self.menuMenu.setTitle(_translate("MainWindow", "Menu"))
self.actionInstructions.setText(_translate("MainWindow", "Credit"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
def Billing ():
Name = self.lineEdit.setText()
Address = self.lineEdit_2.setText()
Email = self.lineEdit_4.setText()
Tel = self.lineEdit_5.setText()
Zip_code = self.lineEdit_6.setText()
City = self.lineEdit_7.setText()
State = self.comboBox.setText()
Country = self.comboBox_2.setText()
def Payment ():
Card_type = self.comboBox_3.setText()
Card_number = self.lineEdit_8.setText()
Card_date = self.comboBox_4.setText()
Card_month = self.comboBox_5.setText()
Card_verif = self.lineEdit_9.setText()
def Item ():
Item_Style = self.comboBox_6.setText()
Item_Name = self.lineEdit_10.setText()
Item_Color = self.lineEdit_11.setText()
Item_Size = self.comboBox_7.set.setText()
self.Addtocart.clicked.connect(self.Add)
def Add (self):
entered_text = "Hello World"
`self.plainTextEdit.setText(entered_text)
生成Qt Designer的class是面向设计的,建议创建一个实现逻辑的class
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
QtWidgets.QMainWindow.__init__(self, parent=parent)
self.setupUi(self)
self.Addtocart.clicked.connect(self.addCart)
def addCart(self):
style = self.comboBox_6.currentText()
name = self.lineEdit_10.text()
color = self.lineEdit_11.text()
size = self.comboBox_7.currentText()
text = "style: {style}, name: {name}, color: {color}, size: {size}".format(style=style, name=name, color=color, size=size)
self.plainTextEdit.setPlainText(text)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = MainWindow()
MainWindow.show()
sys.exit(app.exec_())
我是 QT 设计器和 PYQT5 的新手,我在向我在 GUI 上创建的“添加到购物车”按钮添加功能时遇到问题。该按钮假设从下拉框中获取样式、名称、颜色和项目的大小,并将其显示在下面的控制台日志中。
from PyQt5 import QtCore, QtGui, QtWidgets
from selenium import webdriver
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(927, 701)
MainWindow.setStyleSheet("background-color: rgb(255, 255, 255);")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox.setGeometry(QtCore.QRect(40, 20, 341, 391))
self.groupBox.setStyleSheet("background-color: rgb(255, 255, 255);")
self.groupBox.setObjectName("groupBox")
self.label = QtWidgets.QLabel(self.groupBox)
self.label.setGeometry(QtCore.QRect(10, 30, 46, 41))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.groupBox)
self.label_2.setGeometry(QtCore.QRect(10, 70, 46, 41))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.groupBox)
self.label_3.setGeometry(QtCore.QRect(10, 140, 46, 41))
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(self.groupBox)
self.label_4.setGeometry(QtCore.QRect(10, 180, 46, 41))
self.label_4.setObjectName("label_4")
self.label_5 = QtWidgets.QLabel(self.groupBox)
self.label_5.setGeometry(QtCore.QRect(10, 230, 31, 21))
self.label_5.setObjectName("label_5")
self.label_6 = QtWidgets.QLabel(self.groupBox)
self.label_6.setGeometry(QtCore.QRect(10, 300, 46, 41))
self.label_6.setObjectName("label_6")
self.label_7 = QtWidgets.QLabel(self.groupBox)
self.label_7.setGeometry(QtCore.QRect(10, 260, 46, 41))
self.label_7.setObjectName("label_7")
self.label_8 = QtWidgets.QLabel(self.groupBox)
self.label_8.setGeometry(QtCore.QRect(10, 340, 46, 41))
self.label_8.setObjectName("label_8")
self.lineEdit = QtWidgets.QLineEdit(self.groupBox)
self.lineEdit.setGeometry(QtCore.QRect(60, 40, 113, 20))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(self.groupBox)
self.lineEdit_2.setGeometry(QtCore.QRect(60, 80, 113, 20))
self.lineEdit_2.setObjectName("lineEdit_2")
self.lineEdit_3 = QtWidgets.QLineEdit(self.groupBox)
self.lineEdit_3.setGeometry(QtCore.QRect(60, 110, 113, 20))
self.lineEdit_3.setObjectName("lineEdit_3")
self.lineEdit_4 = QtWidgets.QLineEdit(self.groupBox)
self.lineEdit_4.setGeometry(QtCore.QRect(60, 150, 113, 20))
self.lineEdit_4.setObjectName("lineEdit_4")
self.lineEdit_5 = QtWidgets.QLineEdit(self.groupBox)
self.lineEdit_5.setGeometry(QtCore.QRect(60, 190, 113, 20))
self.lineEdit_5.setObjectName("lineEdit_5")
self.lineEdit_6 = QtWidgets.QLineEdit(self.groupBox)
self.lineEdit_6.setGeometry(QtCore.QRect(60, 230, 51, 20))
self.lineEdit_6.setObjectName("lineEdit_6")
self.lineEdit_7 = QtWidgets.QLineEdit(self.groupBox)
self.lineEdit_7.setGeometry(QtCore.QRect(60, 270, 113, 20))
self.lineEdit_7.setObjectName("lineEdit_7")
self.comboBox = QtWidgets.QComboBox(self.groupBox)
self.comboBox.setGeometry(QtCore.QRect(60, 310, 51, 22))
self.comboBox.setObjectName("comboBox")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox_2 = QtWidgets.QComboBox(self.groupBox)
self.comboBox_2.setGeometry(QtCore.QRect(60, 350, 69, 22))
self.comboBox_2.setObjectName("comboBox_2")
self.comboBox_2.addItem("")
self.groupBox_2 = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox_2.setGeometry(QtCore.QRect(40, 420, 341, 211))
self.groupBox_2.setStyleSheet("background-color: rgb(255, 255, 255);")
self.groupBox_2.setObjectName("groupBox_2")
self.label_9 = QtWidgets.QLabel(self.groupBox_2)
self.label_9.setGeometry(QtCore.QRect(10, 30, 46, 13))
self.label_9.setObjectName("label_9")
self.label_10 = QtWidgets.QLabel(self.groupBox_2)
self.label_10.setGeometry(QtCore.QRect(10, 70, 46, 13))
self.label_10.setObjectName("label_10")
self.label_11 = QtWidgets.QLabel(self.groupBox_2)
self.label_11.setGeometry(QtCore.QRect(10, 110, 46, 13))
self.label_11.setObjectName("label_11")
self.label_12 = QtWidgets.QLabel(self.groupBox_2)
self.label_12.setGeometry(QtCore.QRect(10, 140, 41, 21))
self.label_12.setObjectName("label_12")
self.comboBox_3 = QtWidgets.QComboBox(self.groupBox_2)
self.comboBox_3.setGeometry(QtCore.QRect(70, 30, 81, 22))
self.comboBox_3.setObjectName("comboBox_3")
self.comboBox_3.addItem("")
self.comboBox_3.addItem("")
self.comboBox_3.addItem("")
self.lineEdit_8 = QtWidgets.QLineEdit(self.groupBox_2)
self.lineEdit_8.setGeometry(QtCore.QRect(70, 70, 131, 20))
self.lineEdit_8.setObjectName("lineEdit_8")
self.comboBox_4 = QtWidgets.QComboBox(self.groupBox_2)
self.comboBox_4.setGeometry(QtCore.QRect(70, 110, 41, 22))
self.comboBox_4.setObjectName("comboBox_4")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_4.addItem("")
self.comboBox_5 = QtWidgets.QComboBox(self.groupBox_2)
self.comboBox_5.setGeometry(QtCore.QRect(130, 110, 61, 22))
self.comboBox_5.setObjectName("comboBox_5")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.comboBox_5.addItem("")
self.lineEdit_9 = QtWidgets.QLineEdit(self.groupBox_2)
self.lineEdit_9.setGeometry(QtCore.QRect(70, 150, 51, 21))
self.lineEdit_9.setObjectName("lineEdit_9")
self.groupBox_3 = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox_3.setGeometry(QtCore.QRect(390, 20, 391, 261))
self.groupBox_3.setStyleSheet("background-color: rgb(255, 255, 255);")
self.groupBox_3.setObjectName("groupBox_3")
self.comboBox_6 = QtWidgets.QComboBox(self.groupBox_3)
self.comboBox_6.setGeometry(QtCore.QRect(100, 30, 121, 22))
self.comboBox_6.setObjectName("comboBox_6")
self.comboBox_6.addItem("")
self.comboBox_6.addItem("")
self.comboBox_6.addItem("")
self.comboBox_6.addItem("")
self.comboBox_6.addItem("")
self.comboBox_6.addItem("")
self.comboBox_6.addItem("")
self.comboBox_6.addItem("")
self.comboBox_6.addItem("")
self.comboBox_6.addItem("")
self.label_13 = QtWidgets.QLabel(self.groupBox_3)
self.label_13.setGeometry(QtCore.QRect(40, 20, 46, 41))
self.label_13.setObjectName("label_13")
self.label_14 = QtWidgets.QLabel(self.groupBox_3)
self.label_14.setGeometry(QtCore.QRect(40, 60, 46, 41))
self.label_14.setObjectName("label_14")
self.label_15 = QtWidgets.QLabel(self.groupBox_3)
self.label_15.setGeometry(QtCore.QRect(40, 150, 46, 41))
self.label_15.setObjectName("label_15")
self.label_16 = QtWidgets.QLabel(self.groupBox_3)
self.label_16.setGeometry(QtCore.QRect(40, 100, 51, 41))
self.label_16.setObjectName("label_16")
self.comboBox_7 = QtWidgets.QComboBox(self.groupBox_3)
self.comboBox_7.setGeometry(QtCore.QRect(100, 160, 81, 22))
self.comboBox_7.setObjectName("comboBox_7")
self.comboBox_7.addItem("")
self.comboBox_7.addItem("")
self.comboBox_7.addItem("")
self.comboBox_7.addItem("")
self.comboBox_7.addItem("")
self.comboBox_7.addItem("")
self.comboBox_7.addItem("")
self.comboBox_7.addItem("")
self.lineEdit_10 = QtWidgets.QLineEdit(self.groupBox_3)
self.lineEdit_10.setGeometry(QtCore.QRect(100, 70, 121, 20))
self.lineEdit_10.setObjectName("lineEdit_10")
self.lineEdit_11 = QtWidgets.QLineEdit(self.groupBox_3)
self.lineEdit_11.setGeometry(QtCore.QRect(100, 110, 121, 20))
self.lineEdit_11.setObjectName("lineEdit_11")
self.Addtocart = QtWidgets.QPushButton(self.groupBox_3)
self.Addtocart.setGeometry(QtCore.QRect(120, 210, 141, 23))
self.Addtocart.setObjectName("Addtocart")
self.groupBox_4 = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox_4.setGeometry(QtCore.QRect(390, 300, 401, 241))
self.groupBox_4.setObjectName("groupBox_4")
self.plainTextEdit = QtWidgets.QPlainTextEdit(self.groupBox_4)
self.plainTextEdit.setGeometry(QtCore.QRect(10, 20, 381, 211))
self.plainTextEdit.setObjectName("plainTextEdit")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(450, 572, 111, 41))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(610, 570, 111, 41))
self.pushButton_2.setObjectName("pushButton_2")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 927, 21))
self.menubar.setObjectName("menubar")
self.menuMenu = QtWidgets.QMenu(self.menubar)
self.menuMenu.setObjectName("menuMenu")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionInstructions = QtWidgets.QAction(MainWindow)
self.actionInstructions.setObjectName("actionInstructions")
self.menuMenu.addSeparator()
self.menuMenu.addAction(self.actionInstructions)
self.menubar.addAction(self.menuMenu.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.groupBox.setTitle(_translate("MainWindow", "Billing Shipping"))
self.label.setText(_translate("MainWindow", "Name"))
self.label_2.setText(_translate("MainWindow", "Address"))
self.label_3.setText(_translate("MainWindow", "Email"))
self.label_4.setText(_translate("MainWindow", "Tel"))
self.label_5.setText(_translate("MainWindow", "Zip"))
self.label_6.setText(_translate("MainWindow", "State"))
self.label_7.setText(_translate("MainWindow", "City"))
self.label_8.setText(_translate("MainWindow", "Country"))
self.comboBox.setItemText(0, _translate("MainWindow", "AL"))
self.comboBox.setItemText(1, _translate("MainWindow", "AK"))
self.comboBox.setItemText(2, _translate("MainWindow", "AS"))
self.comboBox.setItemText(3, _translate("MainWindow", "AZ"))
self.comboBox.setItemText(4, _translate("MainWindow", "AR"))
self.comboBox.setItemText(5, _translate("MainWindow", "CA"))
self.comboBox.setItemText(6, _translate("MainWindow", "CO"))
self.comboBox.setItemText(7, _translate("MainWindow", "CT"))
self.comboBox.setItemText(8, _translate("MainWindow", "DE"))
self.comboBox.setItemText(9, _translate("MainWindow", "DC"))
self.comboBox.setItemText(10, _translate("MainWindow", "FM"))
self.comboBox.setItemText(11, _translate("MainWindow", "FL"))
self.comboBox.setItemText(12, _translate("MainWindow", "GA"))
self.comboBox.setItemText(13, _translate("MainWindow", "GU"))
self.comboBox.setItemText(14, _translate("MainWindow", "HI"))
self.comboBox.setItemText(15, _translate("MainWindow", "ID"))
self.comboBox.setItemText(16, _translate("MainWindow", "IL"))
self.comboBox.setItemText(17, _translate("MainWindow", "IN"))
self.comboBox.setItemText(18, _translate("MainWindow", "IA"))
self.comboBox.setItemText(19, _translate("MainWindow", "KS"))
self.comboBox.setItemText(20, _translate("MainWindow", "KY"))
self.comboBox.setItemText(21, _translate("MainWindow", "LA"))
self.comboBox.setItemText(22, _translate("MainWindow", "ME"))
self.comboBox.setItemText(23, _translate("MainWindow", "MH"))
self.comboBox.setItemText(24, _translate("MainWindow", "MD"))
self.comboBox.setItemText(25, _translate("MainWindow", "MA"))
self.comboBox.setItemText(26, _translate("MainWindow", "MI"))
self.comboBox.setItemText(27, _translate("MainWindow", "MN"))
self.comboBox.setItemText(28, _translate("MainWindow", "MS"))
self.comboBox.setItemText(29, _translate("MainWindow", "MO"))
self.comboBox.setItemText(30, _translate("MainWindow", "MT"))
self.comboBox.setItemText(31, _translate("MainWindow", "NE"))
self.comboBox.setItemText(32, _translate("MainWindow", "NV"))
self.comboBox.setItemText(33, _translate("MainWindow", "NH"))
self.comboBox.setItemText(34, _translate("MainWindow", "NJ"))
self.comboBox.setItemText(35, _translate("MainWindow", "NM"))
self.comboBox.setItemText(36, _translate("MainWindow", "NY"))
self.comboBox.setItemText(37, _translate("MainWindow", "NC"))
self.comboBox.setItemText(38, _translate("MainWindow", "ND"))
self.comboBox.setItemText(39, _translate("MainWindow", "MP"))
self.comboBox.setItemText(40, _translate("MainWindow", "OH"))
self.comboBox.setItemText(41, _translate("MainWindow", "OK"))
self.comboBox.setItemText(42, _translate("MainWindow", "OR"))
self.comboBox.setItemText(43, _translate("MainWindow", "PW"))
self.comboBox.setItemText(44, _translate("MainWindow", "PA"))
self.comboBox.setItemText(45, _translate("MainWindow", "PR"))
self.comboBox.setItemText(46, _translate("MainWindow", "RI"))
self.comboBox.setItemText(47, _translate("MainWindow", "SC"))
self.comboBox.setItemText(48, _translate("MainWindow", "SD"))
self.comboBox.setItemText(49, _translate("MainWindow", "TN"))
self.comboBox.setItemText(50, _translate("MainWindow", "TX"))
self.comboBox.setItemText(51, _translate("MainWindow", "UT"))
self.comboBox.setItemText(52, _translate("MainWindow", "VT"))
self.comboBox.setItemText(53, _translate("MainWindow", "VI"))
self.comboBox.setItemText(54, _translate("MainWindow", "VA"))
self.comboBox.setItemText(55, _translate("MainWindow", "WA"))
self.comboBox.setItemText(56, _translate("MainWindow", "WV"))
self.comboBox.setItemText(57, _translate("MainWindow", "WI"))
self.comboBox.setItemText(58, _translate("MainWindow", "WY"))
self.comboBox_2.setItemText(0, _translate("MainWindow", "USA"))
self.groupBox_2.setTitle(_translate("MainWindow", "Payment Info"))
self.label_9.setText(_translate("MainWindow", "Type"))
self.label_10.setText(_translate("MainWindow", "Number"))
self.label_11.setText(_translate("MainWindow", "Exp Date"))
self.label_12.setText(_translate("MainWindow", "CCV"))
self.comboBox_3.setItemText(0, _translate("MainWindow", "Visa"))
self.comboBox_3.setItemText(1, _translate("MainWindow", "American Express"))
self.comboBox_3.setItemText(2, _translate("MainWindow", "Master Card"))
self.comboBox_4.setItemText(0, _translate("MainWindow", "01"))
self.comboBox_4.setItemText(1, _translate("MainWindow", "02"))
self.comboBox_4.setItemText(2, _translate("MainWindow", "03"))
self.comboBox_4.setItemText(3, _translate("MainWindow", "04"))
self.comboBox_4.setItemText(4, _translate("MainWindow", "05"))
self.comboBox_4.setItemText(5, _translate("MainWindow", "06"))
self.comboBox_4.setItemText(6, _translate("MainWindow", "07"))
self.comboBox_4.setItemText(7, _translate("MainWindow", "08"))
self.comboBox_4.setItemText(8, _translate("MainWindow", "09"))
self.comboBox_4.setItemText(9, _translate("MainWindow", "10"))
self.comboBox_4.setItemText(10, _translate("MainWindow", "11"))
self.comboBox_4.setItemText(11, _translate("MainWindow", "12"))
self.comboBox_5.setItemText(0, _translate("MainWindow", "2017"))
self.comboBox_5.setItemText(1, _translate("MainWindow", "2018"))
self.comboBox_5.setItemText(2, _translate("MainWindow", "2019"))
self.comboBox_5.setItemText(3, _translate("MainWindow", "2020"))
self.comboBox_5.setItemText(4, _translate("MainWindow", "2021"))
self.comboBox_5.setItemText(5, _translate("MainWindow", "2022"))
self.comboBox_5.setItemText(6, _translate("MainWindow", "2023"))
self.comboBox_5.setItemText(7, _translate("MainWindow", "2024"))
self.comboBox_5.setItemText(8, _translate("MainWindow", "2025"))
self.comboBox_5.setItemText(9, _translate("MainWindow", "2026"))
self.comboBox_5.setItemText(10, _translate("MainWindow", "2027"))
self.groupBox_3.setTitle(_translate("MainWindow", "Item Finder"))
self.comboBox_6.setItemText(0, _translate("MainWindow", "Jackets"))
self.comboBox_6.setItemText(1, _translate("MainWindow", "Shirts"))
self.comboBox_6.setItemText(2, _translate("MainWindow", "Tops/Sweaters"))
self.comboBox_6.setItemText(3, _translate("MainWindow", "Sweatshirts"))
self.comboBox_6.setItemText(4, _translate("MainWindow", "Pants"))
self.comboBox_6.setItemText(5, _translate("MainWindow", "Shorts"))
self.comboBox_6.setItemText(6, _translate("MainWindow", "Hats"))
self.comboBox_6.setItemText(7, _translate("MainWindow", "accessories"))
self.comboBox_6.setItemText(8, _translate("MainWindow", "Shoes"))
self.comboBox_6.setItemText(9, _translate("MainWindow", "Skate"))
self.label_13.setText(_translate("MainWindow", "Style"))
self.label_14.setText(_translate("MainWindow", "Name"))
self.label_15.setText(_translate("MainWindow", "Size"))
self.label_16.setText(_translate("MainWindow", "Color"))
self.comboBox_7.setItemText(0, _translate("MainWindow", "Small"))
self.comboBox_7.setItemText(1, _translate("MainWindow", "Medium"))
self.comboBox_7.setItemText(2, _translate("MainWindow", "Large"))
self.comboBox_7.setItemText(3, _translate("MainWindow", "30"))
self.comboBox_7.setItemText(4, _translate("MainWindow", "31"))
self.comboBox_7.setItemText(5, _translate("MainWindow", "32"))
self.comboBox_7.setItemText(6, _translate("MainWindow", "33"))
self.comboBox_7.setItemText(7, _translate("MainWindow", "34"))
self.Addtocart.setText(_translate("MainWindow", "Add to Cart"))
self.groupBox_4.setTitle(_translate("MainWindow", "Status"))
self.pushButton.setText(_translate("MainWindow", "START"))
self.pushButton_2.setText(_translate("MainWindow", "STOP"))
self.menuMenu.setTitle(_translate("MainWindow", "Menu"))
self.actionInstructions.setText(_translate("MainWindow", "Credit"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
def Billing ():
Name = self.lineEdit.setText()
Address = self.lineEdit_2.setText()
Email = self.lineEdit_4.setText()
Tel = self.lineEdit_5.setText()
Zip_code = self.lineEdit_6.setText()
City = self.lineEdit_7.setText()
State = self.comboBox.setText()
Country = self.comboBox_2.setText()
def Payment ():
Card_type = self.comboBox_3.setText()
Card_number = self.lineEdit_8.setText()
Card_date = self.comboBox_4.setText()
Card_month = self.comboBox_5.setText()
Card_verif = self.lineEdit_9.setText()
def Item ():
Item_Style = self.comboBox_6.setText()
Item_Name = self.lineEdit_10.setText()
Item_Color = self.lineEdit_11.setText()
Item_Size = self.comboBox_7.set.setText()
self.Addtocart.clicked.connect(self.Add)
def Add (self):
entered_text = "Hello World"
`self.plainTextEdit.setText(entered_text)
生成Qt Designer的class是面向设计的,建议创建一个实现逻辑的class
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
QtWidgets.QMainWindow.__init__(self, parent=parent)
self.setupUi(self)
self.Addtocart.clicked.connect(self.addCart)
def addCart(self):
style = self.comboBox_6.currentText()
name = self.lineEdit_10.text()
color = self.lineEdit_11.text()
size = self.comboBox_7.currentText()
text = "style: {style}, name: {name}, color: {color}, size: {size}".format(style=style, name=name, color=color, size=size)
self.plainTextEdit.setPlainText(text)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = MainWindow()
MainWindow.show()
sys.exit(app.exec_())