消息框内的Python输入框 [英] Python input box inside a message box
问题描述
有什么方法可以使用ctypes库在消息框内打开输入框?到目前为止,我有:
is there any way to have an input box inside of an message box opened with the ctypes library? so far I have:
import ctypes
messageBox = ctypes.windll.user32.MessageBoxA
title = 'Title'
text = 'Message box!'
returnValue = messageBox(None, text, title, 0x40 | 0x1)
print returnValue
,这将给出一个带有图像图标和两个按钮的消息框,我都知道如何更改它们,并且将变量"returnValue"设置为代表所单击按钮的数字.但是,我还需要一个变量,该变量将设置为在消息框中输入的字符串.我需要这个并且不能简单地执行a = raw_input('prompt')的原因是我希望程序本身在后台运行(它将在登录时启动).
and this gives a message box with an image icon and two buttons, both of which I know how to change, and it sets a variable "returnValue" to a number representing the button clicked. However, I also need a variable that will set to a string input in the message box. The reason I need this and I can't just do simple a = raw_input('prompt') is that I want the program itself to run in the background (it would launch itself on logon).
推荐答案
如果您想要一个简单的解决方案,请使用PyMsgBox模块.它使用Python的内置tkinter库创建消息框,包括允许用户键入响应的消息框.用pip install pymsgbox
安装.
If you want a simple solution, use the PyMsgBox module. It uses Python's built-in tkinter library to create message boxes, including ones that let the user type a response. Install it with pip install pymsgbox
.
文档在此处: https://pymsgbox.readthedocs.org/
您想要的代码是:
>>> import pymsgbox
>>> returnValue = pymsgbox.prompt('Message box!', 'Title')
这篇关于消息框内的Python输入框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!