PyQt5:如何改变QInputDialog OkButtonText?
PyQt5: How can change QInputDialog OkButtonText?
首先,我是一名韩国学生。所以我英语不好,请见谅。
我正在使用 PyQt5。但我不知道“如何使用 setOkButtonText()
”
如何使用setOkButtonText()
或setCancelButtonText()
?
以及我在哪里插入这些代码?
下面是我的部分代码:
import sys
import PyQt5
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5 import uic
class MainDialog(QDialog):
def __init__(self):
QDialog.__init__(self, None)
uic.loadUi(WdmUI, self)
self.depositButton.clicked.connect(self.depositClicked)
self.withdrawButton.clicked.connect(self.withdrawClicked)
def withdrawClicked(self):
while True:
money1, ok1 = QInputDialog.getInt\
(self, "Withdraw", "<font face=\"Malgun Gothic\">Input withdraw amount:</font>", 1000, 0, 10000001)
QInputDialog.setOkButtonText(self, "OKOK")
这是它产生的错误:
TypeError: setOkButtonText(self, str): first argument of unbound method must have type 'QInputDialog'
试一试:
import sys
from PyQt5.QtWidgets import (QWidget, QPushButton, QLineEdit, QHBoxLayout,
QInputDialog, QApplication, QDialog)
class Example(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('Input dialog')
btn = QPushButton('Dialog')
btn.clicked.connect(self.showDialog)
self.le = QLineEdit(self)
layout = QHBoxLayout(self)
layout.addWidget(btn)
layout.addWidget(self.le)
def showDialog(self):
dialog = QInputDialog(self)
dialog.setWindowTitle("QInputDialog")
dialog.setLabelText("Enter Value")
dialog.setOkButtonText("OKOK") # +++
dialog.setCancelButtonText("NOT OK") # +++
if dialog.exec_() == QDialog.Accepted:
text = dialog.textValue()
self.le.setText(text)
else:
print("canceled")
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
ex.show()
sys.exit(app.exec_())
首先,我是一名韩国学生。所以我英语不好,请见谅。
我正在使用 PyQt5。但我不知道“如何使用 setOkButtonText()
”
如何使用setOkButtonText()
或setCancelButtonText()
?
以及我在哪里插入这些代码?
下面是我的部分代码:
import sys
import PyQt5
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5 import uic
class MainDialog(QDialog):
def __init__(self):
QDialog.__init__(self, None)
uic.loadUi(WdmUI, self)
self.depositButton.clicked.connect(self.depositClicked)
self.withdrawButton.clicked.connect(self.withdrawClicked)
def withdrawClicked(self):
while True:
money1, ok1 = QInputDialog.getInt\
(self, "Withdraw", "<font face=\"Malgun Gothic\">Input withdraw amount:</font>", 1000, 0, 10000001)
QInputDialog.setOkButtonText(self, "OKOK")
这是它产生的错误:
TypeError: setOkButtonText(self, str): first argument of unbound method must have type 'QInputDialog'
试一试:
import sys
from PyQt5.QtWidgets import (QWidget, QPushButton, QLineEdit, QHBoxLayout,
QInputDialog, QApplication, QDialog)
class Example(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('Input dialog')
btn = QPushButton('Dialog')
btn.clicked.connect(self.showDialog)
self.le = QLineEdit(self)
layout = QHBoxLayout(self)
layout.addWidget(btn)
layout.addWidget(self.le)
def showDialog(self):
dialog = QInputDialog(self)
dialog.setWindowTitle("QInputDialog")
dialog.setLabelText("Enter Value")
dialog.setOkButtonText("OKOK") # +++
dialog.setCancelButtonText("NOT OK") # +++
if dialog.exec_() == QDialog.Accepted:
text = dialog.textValue()
self.le.setText(text)
else:
print("canceled")
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
ex.show()
sys.exit(app.exec_())