im try to activate a tutorial code for wxPython,
the calculator.py...but it gives me the next message
File "C:\Users\AOFU\Desktop\A-PYTHON\calculator.py", line 184, in <module>
app = MyApp(0)
File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7978, in __init__
self._BootstrapApp()
File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7552, in _BootstrapApp
return _core_.PyApp__BootstrapApp(*args, **kwargs)
File "C:\Users\AOFU\Desktop\A-PYTHON\calculator.py", line 179, in OnInit
frame = MyFrame(None, -1, 'calculator.py')
File "C:\Users\AOFU\Desktop\A-PYTHON\calculator.py", line 17, in __init__
wx.EVT_MENU(self, 22, self.OnClose)
AttributeError: 'MyFrame' object has no attribute 'OnClose' -
#!/usr/bin/python
-
-
# calculator.py
-
-
import wx
-
-
class MyFrame(wx.Frame):
-
def __init__(self, parent, id, title):
-
-
wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(300, 250))
-
self.formula = False
-
menubar = wx.MenuBar()
-
file = wx.Menu()
-
file.Append(22, '&Quit', 'Exit Calculator')
-
menubar.Append(file, '&File')
-
self.SetMenuBar(menubar)
-
wx.EVT_MENU(self, 22, self.OnClose)
-
sizer = wx.BoxSizer(wx.VERTICAL)
-
self.display = wx.TextCtrl(self, -1, '', style=wx.TE_RIGHT)
-
sizer.Add(self.display, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 4)
-
-
gs = wx.GridSizer(4, 4, 3, 3)
-
gs.AddMany([(wx.Button(self, 20, 'Cls'), 0, wx.EXPAND),
-
(wx.Button(self, 21, 'Bck'), 0, wx.EXPAND),
-
(wx.StaticText(self, -1, ''), 0, wx.EXPAND),
-
(wx.Button(self, 22, 'Close'), 0, wx.EXPAND),
-
(wx.Button(self, 1, '7'), 0, wx.EXPAND),
-
(wx.Button(self, 2, '8'), 0, wx.EXPAND),
-
(wx.Button(self, 3, '9'), 0, wx.EXPAND),
-
(wx.Button(self, 4, '/'), 0, wx.EXPAND),
-
(wx.Button(self, 5, '4'), 0, wx.EXPAND),
-
(wx.Button(self, 6, '5'), 0, wx.EXPAND),
-
(wx.Button(self, 7, '6'), 0, wx.EXPAND),
-
(wx.Button(self, 8, '*'), 0, wx.EXPAND),
-
(wx.Button(self, 9, '1'), 0, wx.EXPAND),
-
(wx.Button(self, 10, '2'), 0, wx.EXPAND),
-
(wx.Button(self, 11, '3'), 0, wx.EXPAND),
-
(wx.Button(self, 12, '-'), 0, wx.EXPAND),
-
(wx.Button(self, 13, '0'), 0, wx.EXPAND),
-
(wx.Button(self, 14, '.'), 0, wx.EXPAND),
-
(wx.Button(self, 15, '='), 0, wx.EXPAND),
-
(wx.Button(self, 16, '+'), 0, wx.EXPAND) ])
-
-
sizer.Add(gs, 1, wx.EXPAND)
-
-
self.SetSizer(sizer)
-
self.Centre()
-
-
self.Bind(wx.EVT_BUTTON, self.OnClear, id=20)
-
self.Bind(wx.EVT_BUTTON, self.OnBackspace, id=21)
-
self.Bind(wx.EVT_BUTTON, self.OnClose, id=22)
-
self.Bind(wx.EVT_BUTTON, self.OnSeven, id=1)
-
self.Bind(wx.EVT_BUTTON, self.OnEight, id=2)
-
self.Bind(wx.EVT_BUTTON, self.OnNine, id=3)
-
self.Bind(wx.EVT_BUTTON, self.OnDivide, id=4)
-
self.Bind(wx.EVT_BUTTON, self.OnFour, id=5)
-
self.Bind(wx.EVT_BUTTON, self.OnFive, id=6)
-
self.Bind(wx.EVT_BUTTON, self.OnSix, id=7)
-
self.Bind(wx.EVT_BUTTON, self.OnMultiply, id=8)
-
self.Bind(wx.EVT_BUTTON, self.OnOne, id=9)
-
self.Bind(wx.EVT_BUTTON, self.OnTwo, id=10)
-
self.Bind(wx.EVT_BUTTON, self.OnThree, id=11)
-
self.Bind(wx.EVT_BUTTON, self.OnMinus, id=12)
-
self.Bind(wx.EVT_BUTTON, self.OnZero, id=13)
-
self.Bind(wx.EVT_BUTTON, self.OnDot, id=14)
-
self.Bind(wx.EVT_BUTTON, self.OnEqual, id=15)
-
self.Bind(wx.EVT_BUTTON, self.OnPlus, id=16)
-
-
def OnClear(self, event):
-
self.display.Clear()
-
-
def OnBackspace(self, event):
-
formula = self.display.GetValue()
-
self.display.Clear()
-
self.display.SetValue(formula[:-1])
-
-
def OnClose(self, event):
-
self.Close()
-
-
def OnDivide(self, event):
-
if self.formula:
-
return
-
self.display.AppendText('/')
-
-
def OnMultiply(self, event):
-
if self.formula:
-
return
-
self.display.AppendText('*')
-
-
def OnMinus(self, event):
-
if self.formula:
-
return
-
self.display.AppendText('-')
-
-
def OnPlus(self, event):
-
if self.formula:
-
return
-
self.display.AppendText('+')
-
-
def OnDot(self, event):
-
if self.formula:
-
return
-
self.display.AppendText('.')
-
-
def OnEqual(self, event):
-
if self.formula:
-
return
-
formula = self.display.GetValue()
-
self.formula = False
-
try:
-
self.display.Clear()
-
output = eval(formula)
-
self.display.AppendText(str(output))
-
except StandardError:
-
self.display.AppendText("Error")
-
-
def OnZero(self, event):
-
if self.formula:
-
self.display.Clear()
-
self.formula = False
-
self.display.AppendText('0')
-
-
def OnOne(self, event):
-
if self.formula:
-
self.display.Clear()
-
self.formula = False
-
self.display.AppendText('1')
-
-
def OnTwo(self, event):
-
if self.formula:
-
self.display.Clear()
-
self.formula = False
-
self.display.AppendText('2')
-
-
def OnThree(self, event):
-
if self.formula:
-
self.display.Clear()
-
self.formula = False
-
self.display.AppendText('3')
-
-
def OnFour(self, event):
-
if self.formula:
-
self.display.Clear()
-
self.formula = False
-
self.display.AppendText('4')
-
-
def OnFive(self, event):
-
if self.formula:
-
self.display.Clear()
-
self.formula = False
-
self.display.AppendText('5')
-
-
def OnSix(self, event):
-
if self.formula:
-
self.display.Clear()
-
self.formula = False
-
self.display.AppendText('6')
-
-
def OnSeven(self, event):
-
if self.formula:
-
self.display.Clear()
-
self.formula = False
-
self.display.AppendText('7')
-
-
def OnEight(self, event):
-
if self.formula:
-
self.display.Clear()
-
self.formula = False
-
self.display.AppendText('8')
-
-
def OnNine(self, event):
-
if self.formula:
-
self.display.Clear()
-
self.formula = False
-
self.display.AppendText('9')
-
-
class MyApp(wx.App):
-
def OnInit(self):
-
frame = MyFrame(None, -1, 'calculator.py')
-
frame.Show(True)
-
self.SetTopWindow(frame)
-
return True
-
-
app = MyApp(0)
-
app.MainLoop()
-
-
4 3813 bvdet 2,851
Recognized Expert Moderator Specialist
Your indentation is wrong. The functions after the class MyFrame block must be at the same leval as __init__().
ok sorry,...it works...thx...but the calculator doesnt appear
bvdet 2,851
Recognized Expert Moderator Specialist
After correcting your indentation, the application appears to work fine. - #!/usr/bin/python
-
-
# calculator.py
-
-
import wx
-
-
class MyFrame(wx.Frame):
-
def __init__(self, parent, id, title):
-
-
wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(300, 250))
-
self.formula = False
-
menubar = wx.MenuBar()
-
file = wx.Menu()
-
file.Append(22, '&Quit', 'Exit Calculator')
-
menubar.Append(file, '&File')
-
self.SetMenuBar(menubar)
-
wx.EVT_MENU(self, 22, self.OnClose)
-
sizer = wx.BoxSizer(wx.VERTICAL)
-
self.display = wx.TextCtrl(self, -1, '', style=wx.TE_RIGHT)
-
sizer.Add(self.display, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 4)
-
-
gs = wx.GridSizer(4, 4, 3, 3)
-
gs.AddMany([(wx.Button(self, 20, 'Cls'), 0, wx.EXPAND),
-
(wx.Button(self, 21, 'Bck'), 0, wx.EXPAND),
-
(wx.StaticText(self, -1, ''), 0, wx.EXPAND),
-
(wx.Button(self, 22, 'Close'), 0, wx.EXPAND),
-
(wx.Button(self, 1, '7'), 0, wx.EXPAND),
-
(wx.Button(self, 2, '8'), 0, wx.EXPAND),
-
(wx.Button(self, 3, '9'), 0, wx.EXPAND),
-
(wx.Button(self, 4, '/'), 0, wx.EXPAND),
-
(wx.Button(self, 5, '4'), 0, wx.EXPAND),
-
(wx.Button(self, 6, '5'), 0, wx.EXPAND),
-
(wx.Button(self, 7, '6'), 0, wx.EXPAND),
-
(wx.Button(self, 8, '*'), 0, wx.EXPAND),
-
(wx.Button(self, 9, '1'), 0, wx.EXPAND),
-
(wx.Button(self, 10, '2'), 0, wx.EXPAND),
-
(wx.Button(self, 11, '3'), 0, wx.EXPAND),
-
(wx.Button(self, 12, '-'), 0, wx.EXPAND),
-
(wx.Button(self, 13, '0'), 0, wx.EXPAND),
-
(wx.Button(self, 14, '.'), 0, wx.EXPAND),
-
(wx.Button(self, 15, '='), 0, wx.EXPAND),
-
(wx.Button(self, 16, '+'), 0, wx.EXPAND) ])
-
-
sizer.Add(gs, 1, wx.EXPAND)
-
-
self.SetSizer(sizer)
-
self.Centre()
-
-
self.Bind(wx.EVT_BUTTON, self.OnClear, id=20)
-
self.Bind(wx.EVT_BUTTON, self.OnBackspace, id=21)
-
self.Bind(wx.EVT_BUTTON, self.OnClose, id=22)
-
self.Bind(wx.EVT_BUTTON, self.OnSeven, id=1)
-
self.Bind(wx.EVT_BUTTON, self.OnEight, id=2)
-
self.Bind(wx.EVT_BUTTON, self.OnNine, id=3)
-
self.Bind(wx.EVT_BUTTON, self.OnDivide, id=4)
-
self.Bind(wx.EVT_BUTTON, self.OnFour, id=5)
-
self.Bind(wx.EVT_BUTTON, self.OnFive, id=6)
-
self.Bind(wx.EVT_BUTTON, self.OnSix, id=7)
-
self.Bind(wx.EVT_BUTTON, self.OnMultiply, id=8)
-
self.Bind(wx.EVT_BUTTON, self.OnOne, id=9)
-
self.Bind(wx.EVT_BUTTON, self.OnTwo, id=10)
-
self.Bind(wx.EVT_BUTTON, self.OnThree, id=11)
-
self.Bind(wx.EVT_BUTTON, self.OnMinus, id=12)
-
self.Bind(wx.EVT_BUTTON, self.OnZero, id=13)
-
self.Bind(wx.EVT_BUTTON, self.OnDot, id=14)
-
self.Bind(wx.EVT_BUTTON, self.OnEqual, id=15)
-
self.Bind(wx.EVT_BUTTON, self.OnPlus, id=16)
-
-
def OnClear(self, event):
-
self.display.Clear()
-
-
def OnBackspace(self, event):
-
formula = self.display.GetValue()
-
self.display.Clear()
-
self.display.SetValue(formula[:-1])
-
-
def OnClose(self, event):
-
self.Close()
-
-
def OnDivide(self, event):
-
if self.formula:
-
return
-
self.display.AppendText('/')
-
-
def OnMultiply(self, event):
-
if self.formula:
-
return
-
self.display.AppendText('*')
-
-
def OnMinus(self, event):
-
if self.formula:
-
return
-
self.display.AppendText('-')
-
-
def OnPlus(self, event):
-
if self.formula:
-
return
-
self.display.AppendText('+')
-
-
def OnDot(self, event):
-
if self.formula:
-
return
-
self.display.AppendText('.')
-
-
def OnEqual(self, event):
-
if self.formula:
-
return
-
formula = self.display.GetValue()
-
self.formula = False
-
try:
-
self.display.Clear()
-
output = eval(formula)
-
self.display.AppendText(str(output))
-
except StandardError:
-
self.display.AppendText("Error")
-
-
def OnZero(self, event):
-
if self.formula:
-
self.display.Clear()
-
self.formula = False
-
self.display.AppendText('0')
-
-
def OnOne(self, event):
-
if self.formula:
-
self.display.Clear()
-
self.formula = False
-
self.display.AppendText('1')
-
-
def OnTwo(self, event):
-
if self.formula:
-
self.display.Clear()
-
self.formula = False
-
self.display.AppendText('2')
-
-
def OnThree(self, event):
-
if self.formula:
-
self.display.Clear()
-
self.formula = False
-
self.display.AppendText('3')
-
-
def OnFour(self, event):
-
if self.formula:
-
self.display.Clear()
-
self.formula = False
-
self.display.AppendText('4')
-
-
def OnFive(self, event):
-
if self.formula:
-
self.display.Clear()
-
self.formula = False
-
self.display.AppendText('5')
-
-
def OnSix(self, event):
-
if self.formula:
-
self.display.Clear()
-
self.formula = False
-
self.display.AppendText('6')
-
-
def OnSeven(self, event):
-
if self.formula:
-
self.display.Clear()
-
self.formula = False
-
self.display.AppendText('7')
-
-
def OnEight(self, event):
-
if self.formula:
-
self.display.Clear()
-
self.formula = False
-
self.display.AppendText('8')
-
-
def OnNine(self, event):
-
if self.formula:
-
self.display.Clear()
-
self.formula = False
-
self.display.AppendText('9')
-
-
class MyApp(wx.App):
-
def OnInit(self):
-
frame = MyFrame(None, -1, 'calculator.py')
-
frame.Show(True)
-
self.SetTopWindow(frame)
-
return True
-
-
app = MyApp(0)
-
app.MainLoop()
thx.it worked..i was doing that thing wrong..soo wrong...
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: JD |
last post by:
This is more details about my problem, which I already managed
to post as a Python bug to Sourceforge
This problem is not related to the bug I encountered earlier, and
this is related to a...
|
by: JD |
last post by:
I hope I didn't post this twice, but I didn't see my earlier posting,
so I've posted it again. Please excuse of me you see a 2nd one,
but I suspect this might be a problem with our mailer.
...
|
by: Knoppix User |
last post by:
Hi folks
There is obviously something that is escaping me - please help!!
I have cut and pasted the relevant portions of text from a script I am
writing in my quest to learn the Python.
...
|
by: Johnny Lee |
last post by:
Hi,
Look at the follow command in python command line, See what's
interesting?:)
>>> class A:
i = 0
>>> a = A()
>>> b = A()
>>> a.i = 1
>>> print a.i, b.i
|
by: M.N.A.Smadi |
last post by:
HI;
I am having the following error. I am using someone else's code and
all they are doing is pass an argv to a function then
def execute_action(manager, argv):
method_name =...
| |
by: s99999999s2003 |
last post by:
hi
i have script like this:
from fnmatch import fnmatch
from glob import glob
.....
....
f =
r = "d:\\somepath"
pat = "*.bat"
|
by: bob |
last post by:
Hi,
I have this sample python script from the hal sources, but it doesn't work
for me. This is despite other example python scripts I have to help me are
working fine. The problem is that this...
|
by: Teja |
last post by:
Hi all,
What is attribute error? what causes that error, especially with COM
objects?
To be precise :
Attribute Error: LCAS.LabcarController.writeLogWindow()
Here, LCAS.... is a COM...
|
by: johnny |
last post by:
I am getting the following errors:
File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 679, in
_send_output
self.send(msg)
File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 646, in...
|
by: jtbaca |
last post by:
I guess this is in Whatsup module. I just started using python today, so I don't have any idea of what the problem is. Supposedly a collegue is using this script without a problem using an earlier...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
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: 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: 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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |