Flu*_*ard 6 python ctypes messagebox
有没有办法在ctypes库打开的消息框中有一个输入框?到目前为止我有:
import ctypes
messageBox = ctypes.windll.user32.MessageBoxA
title = 'Title'
text = 'Message box!'
returnValue = messageBox(None, text, title, 0x40 | 0x1)
print returnValue
Run Code Online (Sandbox Code Playgroud)
这会给出一个带有图像图标和两个按钮的消息框,这两个按钮我知道如何更改,并将变量"returnValue"设置为表示单击按钮的数字.但是,我还需要一个将在消息框中设置为字符串输入的变量.我需要这个的原因我不能只做简单的a = raw_input('prompt')是我希望程序本身在后台运行(它会在登录时启动).
消息框仅用于消息。你需要的是QDialog. 您可以在 QtDesigner 中创建它(我以这种方式创建了登录对话框,其中 2 个QLineEdit用于用户名和密码,2 个用于语言选择的按钮QDialogButtonBox)QCombobox。您将获得.ui文件,您需要.py在 cmd 中将其转换为以下形式:
pyuic4 -x YourLoginDialogWindow.ui -o YourLoginDialogWindow.py
Run Code Online (Sandbox Code Playgroud)
导入已创建YourLoginDialogWindow.py,您可以使用它并实现您需要的任何方法:
import YourLoginDialogWindow
class YourLoginDialog(QtGui.QDialog):
def __init__(self, parent = None):
super(YourLoginDialog, self).__init__(parent)
self.__ui = YourLoginDialogWindow.Ui_Dialog()
self.__ui.setupUi(self)
...
self.__ui.buttonBox.accepted.connect(self.CheckUserCredentials)
self.__ui.buttonBox.rejected.connect(self.reject)
def GetUsername(self):
return self.__ui.usernameLineEdit.text()
def GetUserPass(self):
return self.__ui.passwordLineEdit.text()
def CheckUserCredentials(self):
#check if user and pass are ok here
#you can use self.GetUsername() and self.GetUserPass() to get them
if THEY_ARE_OK :
self.accept()# this will close dialog and open YourMainProgram in main
else:# message box to inform user that username or password are incorect
QtGui.QMessageBox.about(self,'MESSAGE_APPLICATION_TITLE_STR', 'MESSAGE_WRONG_USERNAM_OR_PASSWORD_STR')
Run Code Online (Sandbox Code Playgroud)
在您的__main__第一个创建登录对话框中,然后在主窗口中...
if __name__ == "__main__":
qtApp = QtGui.QApplication(sys.argv)
loginDlg = YourLoginDialog.YourLoginDialog()
if (not loginDlg.exec_()):
sys.exit(-1)
theApp = YourMainProgram.YourMainProgram( loginDlg.GetUsername(), loginDlg.GetPassword())
qtApp.setActiveWindow(theApp)
theApp.show()
sys.exit(qtApp.exec_())
Run Code Online (Sandbox Code Playgroud)