有没有简单和干净的方法来显示与文本输入支持的Qt4(PyQt4的实际上)一个消息框,而不是从预定义列表只选择按钮?我可以(而且已经部分)通过编写一个自定义类来完成这个,只是为了显示这样的对话框,但是不是更清洁的方法吗?
编辑:感谢Luca Carlon我的工作.但是,万一其他人需要这个,我将在下面发布工作PyQt4代码
from PyQt4.QtGui import QInputDialog
#This code works only inside a method of a widget or window as self must refer to a
#valid widget or window to get the correct modality, although we can give None instead
(text,truth)=QInputDialog.getText(self,"Get text","User name",QLineEdit.Normal,"NoName")
if truth:
#The user has accepted the edit, he/she has clicked OK
print text
else:
#The user has not accepted the edit, he/she has clicked Cancel
print "No change"
Run Code Online (Sandbox Code Playgroud)