Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)

I was working with a simple web-based interpreter using Twisted.web. Basically, you have to submit a block of Python code in a form, and the customer comes and takes it and executes it. I want to be able to make a simple popup message, without having to re-write a whole collection of boilerplate wxPython or TkInter code every time.

I've tried tkMessageBox:

import tkMessageBox

tkMessageBox.showinfo(title="Greetings", message="Hello World!")

But the above code is opening another window in the background with a tk image. I don't want this. I was looking for some simple wxPython code.

1 Answer

0 votes
by (107k points)

For achienving your desired output, you need to use import and single line code like this:

import ctypes  # An included library with Python install.   

ctypes.windll.user32.MessageBoxW(0, "Your text", "Your title", 1)

Or you can also define a function (Mbox) like:

import ctypes  # An included library with Python install.

def Mbox(title, text, style):

    return ctypes.windll.user32.MessageBoxW(0, text, title, style)

Mbox('Your title', 'Your text', 1)

Below are some of the styles:

##  Styles:

##  0 : OK

##  1 : OK | Cancel

##  2 : Abort | Retry | Ignore

##  3 : Yes | No | Cancel

##  4 : Yes | No

##  5 : Retry | Cancel 

##  6 : Cancel | Try Again | Continue

 For the best of career growth, check out Intellipaat’s Python Course and get certified!

Related questions

0 votes
1 answer
asked Nov 25, 2020 in Python by ashely (50.2k points)
0 votes
4 answers
0 votes
1 answer
0 votes
1 answer

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...