Close Windows MEssage box after function call - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Close Windows MEssage box after function call (/thread-10053.html) |
Close Windows MEssage box after function call - ashtona - May-10-2018 Hello, I am trying to simply display a message box on windows 10 while I am copying files/removing directories. I don't need a progress bar or anything super complicated but just simply a window that I open before I begin copying/removing and close after the functions done. Preferably would not like to use tkinter or a gui module, my program does one thing and does not require user input. I am using shutil.copytree and shutil.rmtree Thanks! RE: Close Windows MEssage box after function call - Larz60+ - May-10-2018 message boxes are in most cases GUI by default. A very simple way to do this is to use wxpython. I wrote this for python 3.6.5 on windows 7, but should work on other OS's to install wxpython: pip install wxpython import wx class PopUpMsg(): def __init__(self): self.app = wx.App() def popup_msg(self, message, title=''): """ Display message in standard wx.MessageDialog :param message: (string) Value to be displayed :return: None """ msg_dlg = wx.MessageDialog(None, message, title, wx.OK | wx.ICON_ERROR) val = msg_dlg.ShowModal() msg_dlg.Show() msg_dlg.Destroy() return val def testit(): ''' Test message class :return: None ''' pm = PopUpMsg() val = pm.popup_msg(message='Click OK if it will make you happy!', title='Do Nothing Message Box') if val == wx.ID_OK: print('Yippie') if __name__ == '__main__': testit()you can import this module into any program, and use code similar to testit wherever you need to display a message |