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: -
import wx
-
import os
-
import re
-
def z(a):
-
for i in range(1,13):
-
return i*a
-
class Mine(wx.Frame):
-
def __init__(self,parent,id,title,pos,size,):
-
wx.Frame.__init__(self,parent,id,title,pos,size)
-
self.inp=wx.TextCtrl(self,1,'type here')
-
self.buton=wx.Button(self,2,'answer',pos=(50,50))
-
self.b=wx.Button(self,3,'exit',pos=(120,50))
-
wx.EVT_BUTTON(self,2,self.disp)
-
wx.EVT_BUTTON(self,3,self.end)
-
self.Show(True)
-
def disp(self,eve):
-
x=self.inp.GetValue()
-
d=z(x)
-
f=wx.MessageDialog(self,d,wx.OK)
-
f.ShowModal()
-
f.Destroy()
-
def end(self):
-
raise SystemExit()
-
app=wx.PySimpleApp()
-
frame=Mine(None,wx.ID_ANY,'filefinder',pos=wx.DefaultPosition,size=wx.DefaultSize)
-
app.MainLoop()
-
-
And i got the following error:
-
>>>
-
Traceback (most recent call last):
-
File "C:\Python25\mine.py", line 19, in disp
-
f=wx.MessageDialog(self,d,wx.OK)
-
File "C:\Python25\Lib\site-packages\wx-2.8-msw-ansi\wx\_windows.py", line 2898, in __init__
-
_windows_.MessageDialog_swiginit(self,_windows_.new_MessageDialog(*args, **kwargs))
-
TypeError: String or Unicode type required
-
TypeError: end() takes exactly 1 argument (2 given)
-
>>>
Can someone please show me where i have gone wrong?Thanks
5 3845
You pass the wrong number of arguments to the MessageDialog function
Try this: - f = wx.MessageDialog(self, "Message","Title",wx.OK)
- import wx
-
import os
-
import re
-
-
# Don't hard code ID nubbers! Use NewID()!
-
[wxID_FRAME1, wxID_BUTTON1, wxID_BUTTON2,
-
] = [wx.NewId() for _init_ctrls in range(3)]
-
-
-
class Mine(wx.Frame):
-
def __init__(self, parent, title, pos, size,):
-
wx.Frame.__init__(self, parent, wxID_FRAME1, title, pos, size)
-
self.InputTextCtrl = wx.TextCtrl(self,1,'type here')
-
self.Button1 = wx.Button(self, wxID_BUTTON1, 'answer', pos=(50,50))
-
# Need to Bind() to the event
-
self.Button1.Bind(wx.EVT_BUTTON, self.OnButton1, id=wxID_BUTTON1)
-
-
self.Button2 = wx.Button(self, wxID_BUTTON2, 'exit', pos=(120,50))
-
# Need to Bind() to the event
-
self.Button2.Bind(wx.EVT_BUTTON, self.OnButton2, id=wxID_BUTTON2)
-
-
## wx.EVT_BUTTON(self,2,self.disp)
-
## wx.EVT_BUTTON(self,3,self.end)
-
-
self.Show(True)
-
-
# Use better names for objects and handlers (conventionally start with "On").
-
-
def OnButton1(self, event):
-
x = self.InputTextCtrl.GetValue()
-
## d=z(x)
-
f = wx.MessageDialog(self, "message: x = %s" %x, "title", wx.OK)
-
answer = f.ShowModal()
-
if answer == wx.ID_OK:
-
print "OK"
-
f.Destroy()
-
-
def OnButton2(self, event): # event was left out
-
# let wx cleanup! #
-
self.Destroy()
-
## raise SystemExit()
-
-
-
-
app=wx.PySimpleApp()
-
frame=Mine(None, 'filefinder', pos=wx.DefaultPosition, size=wx.DefaultSize)
-
app.MainLoop()
-
You pass the wrong number of arguments to the MessageDialog function
Try this: - f = wx.MessageDialog(self, "Message","Title",wx.OK)
thank you.
- import wx
-
import os
-
import re
-
-
# Don't hard code ID nubbers! Use NewID()!
-
[wxID_FRAME1, wxID_BUTTON1, wxID_BUTTON2,
-
] = [wx.NewId() for _init_ctrls in range(3)]
-
-
-
class Mine(wx.Frame):
-
def __init__(self, parent, title, pos, size,):
-
wx.Frame.__init__(self, parent, wxID_FRAME1, title, pos, size)
-
self.InputTextCtrl = wx.TextCtrl(self,1,'type here')
-
self.Button1 = wx.Button(self, wxID_BUTTON1, 'answer', pos=(50,50))
-
# Need to Bind() to the event
-
self.Button1.Bind(wx.EVT_BUTTON, self.OnButton1, id=wxID_BUTTON1)
-
-
self.Button2 = wx.Button(self, wxID_BUTTON2, 'exit', pos=(120,50))
-
# Need to Bind() to the event
-
self.Button2.Bind(wx.EVT_BUTTON, self.OnButton2, id=wxID_BUTTON2)
-
-
## wx.EVT_BUTTON(self,2,self.disp)
-
## wx.EVT_BUTTON(self,3,self.end)
-
-
self.Show(True)
-
-
# Use better names for objects and handlers (conventionally start with "On").
-
-
def OnButton1(self, event):
-
x = self.InputTextCtrl.GetValue()
-
## d=z(x)
-
f = wx.MessageDialog(self, "message: x = %s" %x, "title", wx.OK)
-
answer = f.ShowModal()
-
if answer == wx.ID_OK:
-
print "OK"
-
f.Destroy()
-
-
def OnButton2(self, event): # event was left out
-
# let wx cleanup! #
-
self.Destroy()
-
## raise SystemExit()
-
-
-
-
app=wx.PySimpleApp()
-
frame=Mine(None, 'filefinder', pos=wx.DefaultPosition, size=wx.DefaultSize)
-
app.MainLoop()
-
thanks.I actually learned one or two things about wxpython from your message.Thanks again
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
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...
|
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...
|
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,...
|
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...
| |