Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python input box inside a message box

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

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).

like image 608
Fluffball The Wizard Avatar asked Feb 05 '14 02:02

Fluffball The Wizard


People also ask

How do you add an input to a message in Python?

Use the input() function to get Python user input from keyboard. Press the enter key after entering the value. The program waits for user input indefinetly, there is no timeout. The input function returns a string, that you can store in a variable.

How do you input a dialog box in Python?

Here is an example: from turtle import textinput name = textinput("Name", "Please enter your name:") print("Hello", name + "!")


1 Answers

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.

The documentation is here: https://pymsgbox.readthedocs.org/

The code you want is:

>>> import pymsgbox
>>> returnValue = pymsgbox.prompt('Message box!', 'Title')
like image 63
Al Sweigart Avatar answered Sep 29 '22 12:09

Al Sweigart