473,386 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

wxPython Event handling problem

51
Hi everyone.I'm new to wxpython.And i have a little problem.I tried to run the following wxpython app code in IDLE for python25:
Expand|Select|Wrap|Line Numbers
  1. import wx
  2. import os
  3. import re
  4. def z(a):
  5.     for i in range(1,13):
  6.         return i*a
  7. class Mine(wx.Frame):
  8.     def __init__(self,parent,id,title,pos,size,):
  9.         wx.Frame.__init__(self,parent,id,title,pos,size)
  10.         self.inp=wx.TextCtrl(self,1,'type here')
  11.         self.buton=wx.Button(self,2,'answer',pos=(50,50))
  12.         self.b=wx.Button(self,3,'exit',pos=(120,50))
  13.         wx.EVT_BUTTON(self,2,self.disp)
  14.         wx.EVT_BUTTON(self,3,self.end)
  15.         self.Show(True)
  16.     def disp(self,eve):
  17.         x=self.inp.GetValue()
  18.         d=z(x)
  19.         f=wx.MessageDialog(self,d,wx.OK)
  20.         f.ShowModal()
  21.         f.Destroy()
  22.     def end(self):
  23.         raise SystemExit()
  24. app=wx.PySimpleApp()
  25. frame=Mine(None,wx.ID_ANY,'filefinder',pos=wx.DefaultPosition,size=wx.DefaultSize)
  26. app.MainLoop()
  27.  
  28. And i got the following error:
  29.   >>> 
  30. Traceback (most recent call last):
  31.   File "C:\Python25\mine.py", line 19, in disp
  32.     f=wx.MessageDialog(self,d,wx.OK)
  33.   File "C:\Python25\Lib\site-packages\wx-2.8-msw-ansi\wx\_windows.py", line 2898, in __init__
  34.     _windows_.MessageDialog_swiginit(self,_windows_.new_MessageDialog(*args, **kwargs))
  35. TypeError: String or Unicode type required
  36. TypeError: end() takes exactly 1 argument (2 given)
  37. >>> 
Can someone please show me where i have gone wrong?Thanks
Apr 13 '07 #1
5 3845
You pass the wrong number of arguments to the MessageDialog function

Try this:
Expand|Select|Wrap|Line Numbers
  1. f = wx.MessageDialog(self, "Message","Title",wx.OK)
Apr 13 '07 #2
bartonc
6,596 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. import wx
  2. import os
  3. import re
  4.  
  5. # Don't hard code ID nubbers! Use NewID()!
  6. [wxID_FRAME1, wxID_BUTTON1, wxID_BUTTON2,
  7. ] = [wx.NewId() for _init_ctrls in range(3)]
  8.  
  9.  
  10. class Mine(wx.Frame):
  11.     def __init__(self, parent, title, pos, size,):
  12.         wx.Frame.__init__(self, parent, wxID_FRAME1, title, pos, size)
  13.         self.InputTextCtrl = wx.TextCtrl(self,1,'type here')
  14.         self.Button1 = wx.Button(self, wxID_BUTTON1, 'answer', pos=(50,50))
  15.         # Need to Bind() to the event
  16.         self.Button1.Bind(wx.EVT_BUTTON, self.OnButton1, id=wxID_BUTTON1)
  17.  
  18.         self.Button2 = wx.Button(self, wxID_BUTTON2, 'exit', pos=(120,50))
  19.         # Need to Bind() to the event
  20.         self.Button2.Bind(wx.EVT_BUTTON, self.OnButton2, id=wxID_BUTTON2)
  21.  
  22. ##        wx.EVT_BUTTON(self,2,self.disp)
  23. ##        wx.EVT_BUTTON(self,3,self.end)
  24.  
  25.         self.Show(True)
  26.  
  27.     # Use better names for objects and handlers (conventionally start with "On").
  28.  
  29.     def OnButton1(self, event):
  30.         x = self.InputTextCtrl.GetValue()
  31. ##        d=z(x)
  32.         f = wx.MessageDialog(self, "message: x = %s" %x, "title", wx.OK)
  33.         answer = f.ShowModal()
  34.         if answer == wx.ID_OK:
  35.             print "OK"
  36.         f.Destroy()
  37.  
  38.     def OnButton2(self, event):  # event was left out
  39.         # let wx cleanup! #
  40.         self.Destroy()
  41. ##        raise SystemExit()
  42.  
  43.  
  44.  
  45. app=wx.PySimpleApp()
  46. frame=Mine(None, 'filefinder', pos=wx.DefaultPosition, size=wx.DefaultSize)
  47. app.MainLoop()
  48.  
Apr 13 '07 #3
dynamo
51
You pass the wrong number of arguments to the MessageDialog function

Try this:
Expand|Select|Wrap|Line Numbers
  1. f = wx.MessageDialog(self, "Message","Title",wx.OK)
thank you.
Apr 14 '07 #4
dynamo
51
Expand|Select|Wrap|Line Numbers
  1. import wx
  2. import os
  3. import re
  4.  
  5. # Don't hard code ID nubbers! Use NewID()!
  6. [wxID_FRAME1, wxID_BUTTON1, wxID_BUTTON2,
  7. ] = [wx.NewId() for _init_ctrls in range(3)]
  8.  
  9.  
  10. class Mine(wx.Frame):
  11.     def __init__(self, parent, title, pos, size,):
  12.         wx.Frame.__init__(self, parent, wxID_FRAME1, title, pos, size)
  13.         self.InputTextCtrl = wx.TextCtrl(self,1,'type here')
  14.         self.Button1 = wx.Button(self, wxID_BUTTON1, 'answer', pos=(50,50))
  15.         # Need to Bind() to the event
  16.         self.Button1.Bind(wx.EVT_BUTTON, self.OnButton1, id=wxID_BUTTON1)
  17.  
  18.         self.Button2 = wx.Button(self, wxID_BUTTON2, 'exit', pos=(120,50))
  19.         # Need to Bind() to the event
  20.         self.Button2.Bind(wx.EVT_BUTTON, self.OnButton2, id=wxID_BUTTON2)
  21.  
  22. ##        wx.EVT_BUTTON(self,2,self.disp)
  23. ##        wx.EVT_BUTTON(self,3,self.end)
  24.  
  25.         self.Show(True)
  26.  
  27.     # Use better names for objects and handlers (conventionally start with "On").
  28.  
  29.     def OnButton1(self, event):
  30.         x = self.InputTextCtrl.GetValue()
  31. ##        d=z(x)
  32.         f = wx.MessageDialog(self, "message: x = %s" %x, "title", wx.OK)
  33.         answer = f.ShowModal()
  34.         if answer == wx.ID_OK:
  35.             print "OK"
  36.         f.Destroy()
  37.  
  38.     def OnButton2(self, event):  # event was left out
  39.         # let wx cleanup! #
  40.         self.Destroy()
  41. ##        raise SystemExit()
  42.  
  43.  
  44.  
  45. app=wx.PySimpleApp()
  46. frame=Mine(None, 'filefinder', pos=wx.DefaultPosition, size=wx.DefaultSize)
  47. app.MainLoop()
  48.  
thanks.I actually learned one or two things about wxpython from your message.Thanks again
Apr 14 '07 #5
bartonc
6,596 Expert 4TB
thanks.I actually learned one or two things about wxpython from your message.Thanks again
You are welcome. That's what TheScripts is all about.

Keep posting,
Barton
Apr 14 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: wang xiaoyu | last post by:
Hello: i want use activex in wxpython program,but when i use MakeActiveXClass an exception occurs. this is my source code dealing the DICOM ocx.I must note that in this program "hwtxcontrol" is...
3
by: Robert | last post by:
Hello list, could somebody point me to a good reference about wxPython event handling? I have seen many examples but which one is the best. Waht are the advantages and disadvantages? Can you...
7
by: SeeBelow | last post by:
Do many people think that wxPython should replace Tkinter? Is this likely to happen? I ask because I have just started learning Tkinter, and I wonder if I should abandon it in favor of...
5
by: fooooo | last post by:
This is a network app, written in wxPython and the socket module. This is what I want to happen: GUI app starts. User clicks a button to 'start' the work of the app. When start is pressed, a new...
5
by: Jared Russell | last post by:
I've recently decided to try my hand at GUI programming with wxPython, and I've got a couple questions about the general conventions regarding it. To mess around with it, I decided to create a...
9
by: zxo102 | last post by:
Hi everyone, I am using a python socket server to collect data from a socket client and then control a image location ( wxpython) with the data, i.e. moving the image around in the wxpython frame....
1
by: defireman | last post by:
Hi, Sorry for asking a newbie question, but I am currently using wxPython 2.6, and I don't know how to get the properties of an event object in wxPython when handling events. Is there some sort of...
4
by: Jimmy | last post by:
hi, all I'm having a problem with creating custom events in wxpython. I have a class A handling some data processing work and another class B of GUI matter. I need GUI to display information...
16
by: Andrea Gavana | last post by:
Hi Diez & All, Do you mind explaining "why" you find it *buttugly*? I am asking just out of curiosity, obviously. I am so biased towards wxPython that I won't make any comment on this thread...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.