Python Forum
Close Windows MEssage box after function call
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Close Windows MEssage box after function call
#1
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!
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 802 May-02-2023, 08:40 AM
Last Post: Gribouillis
Question Help with function - encryption - messages - NameError: name 'message' is not defined MrKnd94 4 2,916 Nov-11-2022, 09:03 PM
Last Post: deanhystad
  how to call an object in another function in Maya bstout 0 2,090 Apr-05-2021, 07:12 PM
Last Post: bstout
  In this function y initially has no value, but a call to foo() gives no error. Why? Pedroski55 8 3,513 Dec-19-2020, 07:30 AM
Last Post: ndc85430
  Struggling for the past hour to define function and call it back godlyredwall 2 2,233 Oct-29-2020, 02:45 PM
Last Post: deanhystad
  list call problem in generator function using iteration and recursive calls postta 1 1,922 Oct-24-2020, 09:33 PM
Last Post: bowlofred
  function call at defined system time? Holon 5 3,256 Oct-06-2020, 03:58 PM
Last Post: snippsat
  How to call/read function for all elements in my list in python johnny_sav1992 1 2,093 Jul-27-2020, 04:19 PM
Last Post: buran
  Python: Call function with variabele? Ending in error. efclem 5 2,972 Apr-22-2020, 02:35 PM
Last Post: buran
  How to mock an object that is created during function call? Schlangenversteher 0 1,981 Jan-31-2020, 01:36 PM
Last Post: Schlangenversteher

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020