Tuesday, 1 September 2015

// // Leave a Comment

My ecounter with wxpython

I was trying to program a graphical user interface today for one of my projects when I ran into a very frustrating bug when I had barely started. I had always been a fan of Tkinter (I just have a feel there’s a unique reason it was selected to be shipped along with python) but I decided to wet my hands with wxpython today. I had the following lines of codes




 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
import wx.App

class MyApp(wx.App): 

    def OnInit(self):

        wx.MessageBox('hello kelvin', 'wxApp') 

     return True

app = MyApp()

app.mainloop()


The seemingly correct code kept throwing this error at me
>>> 

Traceback (most recent call last):
File "C:\Python27\wx.py", line 1, in
import wx.App
File "C:\Python27\wx.py", line 1, in
import wx.App
ImportError: No module named App
>>> 
I went on for minutes trying to decipher where the bug was coming from only to notice that I saved the file with wx.py (which obviously is the same name with the module i imported). Hence what I had was my own module importing itself! :D
Moral of the story: avoid saving your program with the name of a module to avoid running into troubles of conflicting module names, rename your program and delete the already created python compiled file(.pyc) if you’ve already made the mistake and rerun your program.
Thanks for reading!

0 comments:

Post a Comment