Tuesday, 15 February 2011

python - win32api.messagebox gets called on program start -


I have a very simple Python program that I'm using to get acquainted with Win32api message calls. I put a line in my program

  mywin ['button'] Onclick = win32api.MessageBox (0, 'hello', 'title')  

The problem is that as soon as the program starts, as soon as the message box is displayed and when the button is clicked It does not appear then it goes. Any thoughts that I am doing wrong?

Here is my complete code:

  imported import win32api gui.Window (name = 'mywin', title = u 'gui2py minimum app', resizable = true, Height = '459px', width = '400px', image = '',) gui.Button (label = u 'click me!', Name = 'button', left = '8', top = '115' Default = true, guardian = 'mewin',) # Get reference to the top-level window: mywin = gui.get ("mywin") mywin ['button']. Onclick = win32api if name == "main": mywin.show () gui.main_loop ()  

You are specifying the attribute in win32api.MessageBox calling back value . >. Doing is different from doing this:

  value = win32api.MessageBox (0, 'hello', 'title') mywin ['button']. Onclick = value  

To resolve the problem, you can:

  mywin ['button']. Onclick = Lambda: win32api.MessageBox (0, 'hello', 'title')  

Specifies the code given above to the .click attribute on the lambda function is. When the button is clicked, the lambda will be called and the win32api.MessageBox (0, 'hello', 'title') code will be executed.


No comments:

Post a Comment