473,797 Members | 3,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wxPython Event handling problem

51 New Member
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 3860
Arnold Schuur
36 New Member
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 Recognized Expert Expert
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 New Member
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 New Member
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 Recognized Expert Expert
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
6001
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 a ocx developed my me use vc6,this ocx works fine in wxpython. but you can see i only change this ocx with a new DICOM ocx and set up eventClass,
3
2889
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 also have a short look at the example below and give me some comments, please? Example:
7
11908
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 wxPython. Mitchell Timin -- "Many are stubborn in pursuit of the path they have chosen, few in
5
10677
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 thread is spawned (threading module) and this thread starts listening for data on a socket. When someone connects, a new thread is spawned, It needs to do I/O on that socket and open a GUI window so the user can communicate with the client...
5
1429
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 small app to check my Gmail. I want something that will just sit in my system tray checking for new emails every ten minutes or so. As such, I have no need for an actual window anywhere. So I'm wondering if I should still use a Frame or not. ...
9
5558
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. But the "app.MainLoop()" in wxpython looks like conflicting with the "while 1:" in socket server. After I commented the "app.MainLoop()", everything is working except two things: 1. if I click anywhere on the screen with the mouse, the image is...
1
2106
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 documentation that I can use? for example: def OnEvent(self, event): #code here I would like to see a list of all properties for that event. How would I do this? (I searched for quite a bit, but I can't seem to find good...
4
2853
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 when data in A is updated. I know cutom events in wxpython may work. But I found no material paricularly helpful :(
16
2419
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 in particular, but I am curious to know why some people find it "ugly" or "bad" or whatever. It has its own bugs and missing features, of course, but it is one of the major GUI player in the arena, together with PyQt and PyGTK.
0
10468
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10245
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10205
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9063
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5458
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.