iT邦幫忙

0

Python PyQt5 QLineEdit無法使用英文輸入法輸入文字、第二個功能無法使用

新手無基礎菜問題
我的OS是win10

  1. 目前在QLineEdit使用中文輸入法的數字鍵盤,可以正常輸入,但切換成英文模式卻毫無動作、而且Backspace也毫無作用,不曉得發生什麼問題。
  2. 不曉得格式是否寫錯,只要有兩個def存在,上面那個會有作用,但下面的都無法執行,請問要如何調整?感恩各位大大。

P.s抱歉因為網址是工作用的,恕小弟用XXX替代

from PyQt5 import QtWidgets, QtGui, QtCore
from AutoSN.AutoSN_UI import Ui_mainWindow
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import sys


class MainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = Ui_mainWindow()
        self.ui.setupUi(self)

    #新增序號

        self.ui.sn_enter.keyPressEvent = self.keyPressEvent
    def keyPressEvent(self, e):
        if e.key() == QtCore.Qt.Key_Return or e.key() == QtCore.Qt.Key_Enter and self.ui.sn_enter.text() != "":
            self.ui.collect_sn.addItem(self.ui.sn_enter.text())
            self.ui.sn_enter.clear()



     # 送出單據的按紐
        self.ui.to_order.clicked.connect(self.to_order_but)
    def to_order_but(self):
        order = self.ui.order_numb.text()
        account = self.ui.account.text()
        password = self.ui.pwd.text()

        driver = webdriver.Chrome()
        driver.implicitly_wait(10)
        driver.get(
                'http://' + account + ':' + password + '@system.Xxxxxx.net/xxxxxx/ordersystem.php?toformid=' + order)


app = QtWidgets.QApplication([])
window = MainWindow()
window.show()
sys.exit(app.exec_())

UI的code

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_mainWindow(object):
    def setupUi(self, mainWindow):
        mainWindow.setObjectName("mainWindow")
        mainWindow.resize(510, 832)
        self.centralwidget = QtWidgets.QWidget(mainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.order_numb = QtWidgets.QLineEdit(self.centralwidget)
        self.order_numb.setGeometry(QtCore.QRect(40, 10, 241, 20))
        self.order_numb.setObjectName("order_numb")
        self.to_order = QtWidgets.QPushButton(self.centralwidget)
        self.to_order.setGeometry(QtCore.QRect(70, 40, 191, 41))
        self.to_order.setObjectName("to_order")
        self.radio_sn = QtWidgets.QRadioButton(self.centralwidget)
        self.radio_sn.setGeometry(QtCore.QRect(50, 90, 83, 16))
        self.radio_sn.setObjectName("radio_sn")
        self.radio_fsn = QtWidgets.QRadioButton(self.centralwidget)
        self.radio_fsn.setGeometry(QtCore.QRect(190, 90, 83, 16))
        self.radio_fsn.setObjectName("radio_fsn")
        self.regi_sn = QtWidgets.QPushButton(self.centralwidget)
        self.regi_sn.setGeometry(QtCore.QRect(60, 470, 201, 41))
        self.regi_sn.setObjectName("regi_sn")
        self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox.setGeometry(QtCore.QRect(10, 700, 301, 91))
        self.groupBox.setObjectName("groupBox")
        self.account = QtWidgets.QLineEdit(self.groupBox)
        self.account.setGeometry(QtCore.QRect(80, 20, 113, 20))
        self.account.setObjectName("account")
        self.pwd = QtWidgets.QLineEdit(self.groupBox)
        self.pwd.setGeometry(QtCore.QRect(80, 60, 113, 20))
        self.pwd.setObjectName("pwd")
        self.groupBox_2 = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox_2.setGeometry(QtCore.QRect(0, 540, 311, 151))
        self.groupBox_2.setObjectName("groupBox_2")
        self.add_note = QtWidgets.QPlainTextEdit(self.groupBox_2)
        self.add_note.setGeometry(QtCore.QRect(10, 50, 291, 91))
        self.add_note.setObjectName("add_note")
        self.add_note_sn = QtWidgets.QLineEdit(self.groupBox_2)
        self.add_note_sn.setGeometry(QtCore.QRect(10, 20, 113, 20))
        self.add_note_sn.setObjectName("add_note_sn")
        self.sn_enter = QtWidgets.QLineEdit(self.centralwidget)
        self.sn_enter.setGeometry(QtCore.QRect(100, 120, 161, 31))
        self.sn_enter.setObjectName("sn_enter")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(50, 130, 47, 12))
        self.label.setObjectName("label")
        self.collect_sn = QtWidgets.QListWidget(self.centralwidget)
        self.collect_sn.setGeometry(QtCore.QRect(40, 160, 231, 291))
        self.collect_sn.setObjectName("collect_sn")
        self.test_button = QtWidgets.QPushButton(self.centralwidget)
        self.test_button.setGeometry(QtCore.QRect(280, 120, 75, 23))
        self.test_button.setObjectName("test_button")
        mainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(mainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 510, 21))
        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", "序號自動輸入"))
        self.to_order.setText(_translate("mainWindow", "前往單據"))
        self.radio_sn.setText(_translate("mainWindow", "自編序號"))
        self.radio_fsn.setText(_translate("mainWindow", "原廠序號"))
        self.regi_sn.setText(_translate("mainWindow", "登錄序號"))
        self.groupBox.setTitle(_translate("mainWindow", "帳號密碼"))
        self.groupBox_2.setTitle(_translate("mainWindow", "追加序號/註記"))
        self.label.setText(_translate("mainWindow", "刷入序號"))
        self.test_button.setText(_translate("mainWindow", "PushButton"))

尚未有邦友回答

立即登入回答