正如标题所述,我正在尝试使此键盘有效,并在此过程中学习一些编码。
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.setWindowModality(QtCore.Qt.NonModal)
MainWindow.resize(631, 803)
MainWindow.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
MainWindow.setMouseTracking(True)
MainWindow.setFocusPolicy(QtCore.Qt.ClickFocus)
MainWindow.setAcceptDrops(True)
MainWindow.setDockOptions(QtWidgets.QMainWindow.AllowTabbedDocks|QtWidgets.QMainWindow.AnimatedDocks|QtWidgets.QMainWindow.GroupedDragging)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.widget_num = QtWidgets.QWidget(self.centralwidget)
self.widget_num.setGeometry(QtCore.QRect(290, 310, 320, 191))
font = QtGui.QFont()
font.setBold(True)
font.setItalic(False)
font.setUnderline(True)
font.setWeight(75)
font.setStrikeOut(False)
font.setKerning(True)
self.widget_num.setFont(font)
self.widget_num.setInputMethodHints(QtCore.Qt.ImhNone)
self.widget_num.setObjectName("widget_num")
self.gridLayout = QtWidgets.QGridLayout(self.widget_num)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.pushButton_five = QtWidgets.QPushButton(self.widget_num)
self.pushButton_five.setObjectName("pushButton_five")
self.gridLayout.addWidget(self.pushButton_five, 1, 1, 1, 1)
self.pushButton_two = QtWidgets.QPushButton(self.widget_num)
self.pushButton_two.setObjectName("pushButton_two")
self.gridLayout.addWidget(self.pushButton_two, 0, 1, 1, 1)
self.pushButton_one = QtWidgets.QPushButton(self.widget_num)
self.pushButton_one.setObjectName("pushButton_one")
self.gridLayout.addWidget(self.pushButton_one, 0, 0, 1, 1)
self.pushButton_eight = QtWidgets.QPushButton(self.widget_num)
self.pushButton_eight.setObjectName("pushButton_eight")
self.gridLayout.addWidget(self.pushButton_eight, 2, 1, 1, 1)
self.pushButton_three = QtWidgets.QPushButton(self.widget_num)
self.pushButton_three.setObjectName("pushButton_three")
self.gridLayout.addWidget(self.pushButton_three, 0, 2, 1, 1)
self.pushButton_out = QtWidgets.QPushButton(self.widget_num)
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.pushButton_out.setFont(font)
self.pushButton_out.setObjectName("pushButton_out")
self.gridLayout.addWidget(self.pushButton_out, 3, 2, 1, 1)
self.pushButton_four = QtWidgets.QPushButton(self.widget_num)
self.pushButton_four.setObjectName("pushButton_four")
self.gridLayout.addWidget(self.pushButton_four, 1, 0, 1, 1)
self.pushButton_nine = QtWidgets.QPushButton(self.widget_num)
self.pushButton_nine.setObjectName("pushButton_nine")
self.gridLayout.addWidget(self.pushButton_nine, 2, 2, 1, 1)
self.pushButton_zero = QtWidgets.QPushButton(self.widget_num)
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.pushButton_zero.setFont(font)
self.pushButton_zero.setFlat(False)
self.pushButton_zero.setObjectName("pushButton_zero")
self.gridLayout.addWidget(self.pushButton_zero, 3, 1, 1, 1)
self.pushButton_seven = QtWidgets.QPushButton(self.widget_num)
self.pushButton_seven.setObjectName("pushButton_seven")
self.gridLayout.addWidget(self.pushButton_seven, 2, 0, 1, 1)
self.pushButton_enter = QtWidgets.QPushButton(self.widget_num)
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.pushButton_enter.setFont(font)
self.pushButton_enter.setObjectName("pushButton_enter")
self.gridLayout.addWidget(self.pushButton_enter, 3, 3, 1, 1)
self.pushButton_bckspc = QtWidgets.QPushButton(self.widget_num)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_bckspc.sizePolicy().hasHeightForWidth())
self.pushButton_bckspc.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setBold(True)
font.setItalic(False)
font.setWeight(75)
self.pushButton_bckspc.setFont(font)
self.pushButton_bckspc.setObjectName("pushButton_bckspc")
self.gridLayout.addWidget(self.pushButton_bckspc, 1, 3, 1, 1)
self.pushButton_in = QtWidgets.QPushButton(self.widget_num)
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.pushButton_in.setFont(font)
self.pushButton_in.setObjectName("pushButton_in")
self.gridLayout.addWidget(self.pushButton_in, 3, 0, 1, 1)
self.pushButton_six = QtWidgets.QPushButton(self.widget_num)
self.pushButton_six.setObjectName("pushButton_six")
self.gridLayout.addWidget(self.pushButton_six, 1, 2, 1, 1)
self.pushButton_clear = QtWidgets.QPushButton(self.widget_num)
font = QtGui.QFont()
font.setBold(True)
font.setItalic(True)
font.setWeight(75)
self.pushButton_clear.setFont(font)
self.pushButton_clear.setObjectName("pushButton_clear")
self.gridLayout.addWidget(self.pushButton_clear, 0, 3, 1, 1)
self.pushButton_exit = QtWidgets.QPushButton(self.widget_num)
font = QtGui.QFont()
font.setBold(True)
font.setItalic(False)
font.setWeight(75)
self.pushButton_exit.setFont(font)
self.pushButton_exit.setObjectName("pushButton_exit")
self.gridLayout.addWidget(self.pushButton_exit, 2, 3, 1, 1)
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(290, 280, 311, 20))
self.lineEdit.setObjectName("lineEdit")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(300, 250, 61, 16))
self.label.setObjectName("label")
self.listView = QtWidgets.QListView(self.centralwidget)
self.listView.setGeometry(QtCore.QRect(360, 10, 256, 241))
self.listView.setObjectName("listView")
MainWindow.setCentralWidget(self.centralwidget)
self.statusBar = QtWidgets.QStatusBar(MainWindow)
self.statusBar.setObjectName("statusBar")
MainWindow.setStatusBar(self.statusBar)
self.actionNew = QtWidgets.QAction(MainWindow)
self.actionNew.setCheckable(True)
self.actionNew.setObjectName("actionNew")
self.actionOpen = QtWidgets.QAction(MainWindow)
self.actionExit_Ctrl_X = QtWidgets.QAction(MainWindow)
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton_five.setText(_translate("MainWindow", "5"))
self.pushButton_two.setText(_translate("MainWindow", "2"))
self.pushButton_one.setText(_translate("MainWindow", "1"))
self.pushButton_eight.setText(_translate("MainWindow", "8"))
self.pushButton_three.setText(_translate("MainWindow", "3"))
self.pushButton_out.setText(_translate("MainWindow", "OUT"))
self.pushButton_four.setText(_translate("MainWindow", "4"))
self.pushButton_nine.setText(_translate("MainWindow", "9"))
self.pushButton_zero.setText(_translate("MainWindow", "0"))
self.pushButton_seven.setText(_translate("MainWindow", "7"))
self.pushButton_enter.setText(_translate("MainWindow", "ENTER"))
self.pushButton_bckspc.setText(_translate("MainWindow", "←"))
self.pushButton_in.setText(_translate("MainWindow", "IN"))
self.pushButton_six.setText(_translate("MainWindow", "6"))
self.pushButton_clear.setText(_translate("MainWindow", "Clear"))
self.pushButton_exit.setText(_translate("MainWindow", "Exit"))
self.label.setText(_translate("MainWindow", "Entry Field"))
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_())