Error Message that I can't explain.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • josh001
    New Member
    • Jul 2008
    • 19

    Error Message that I can't explain.

    This Error message pops up every time I run my program using Python Shell and won't open at all when I don't use Shell.

    Code:
     
    Traceback (most recent call last):
      File "C:\Documents and Settings\Joshua Leihe\My Documents\My Projects\NewProjects\Joshua\Python projects\French quiz\French Quiz_17.pyw.pyw", line 440, in <module>
        win.start()
      File "C:\Documents and Settings\Joshua Leihe\My Documents\My Projects\NewProjects\Joshua\Python projects\French quiz\French Quiz_17.pyw.pyw", line 179, in start
        self.Words_Left.SetLabel('You have ' + str(self.wordsleft) +
      File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 14505, in __getattr__
        raise PyDeadObjectError(self.attrStr % self._name)
    PyDeadObjectError: The C++ part of the StaticText object has been deleted, attribute access no longer allowed.
    Any idea what this means and how I can fix it?

    Thanks,
    Josh
  • kaarthikeyapreyan
    New Member
    • Apr 2007
    • 106

    #2
    Could u post your code so that v can figure out the solution for it.

    Comment

    • josh001
      New Member
      • Jul 2008
      • 19

      #3
      It's kind of long...

      It's a lot of code and I haven't sorted it for easy reading yet. (until it's finished I don't how I would sort it while still trying to figure out how to make it work)
      But here it is.

      Code:
       
      import wx, shelve, os
      from random import randrange as ran
      from pprint import pprint 
      class FrenchQuiz:
          def start(self):
              self.app = wx.App()
              #Define all windows
              self.win = wx.Frame(None,
                                  title='French Quiz',
                                  size=(500, 500,),
                                  pos=(400, 250),
                                  style=wx.CLOSE_BOX | wx.CAPTION | wx.SYSTEM_MENU)
              self.win.SetBackgroundColour('Black')
              OpenDLG = wx.FileDialog(
                  self.win,
                  message='Please choose the quiz or quizes that you wish to use.',
                  defaultDir=os.getcwd(),
                  defaultFile='',
                  wildcard='*.*',
                  style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR)
              self.AllWords = {}
              paths = OpenDLG.GetPaths()
              wordlistnum = -1
              if OpenDLG.ShowModal() == wx.ID_OK:
                  for path in paths:
                      try:
                          print path
                      except:
                          KeyError
                      textfile = open(path)
                      words = textfile.readlines()
                      print words#######
                      french = []
                      english = []
                      Pass = 'no'
                      wordlistnum +=1
                      for word in words:
                          if Pass == 'yes':
                              english.append(word[0:-2])
                          if '#english#' in word:
                              Pass = 'yes'
                          if Pass == 'no':
                              if '#english#' not in word:
                                  french.append(word[0:-2])
                      #print french##############
                      #print english##############
                      self.AllWords.update(
                          {wordlistnum: {'French': french, 'English': english}})
                      #print 'yes'##############
                      #print self.AllWords##############
       
       
              self.win.Show()
      #MainWinStatusBar
              self.win.CreateStatusBar()
              self.win.SetStatusText('Hello')
      #MainWinStartUp
              self.Prompt = wx.StaticText(self.win, -1,
                                          'Please choose one of the folowing',
                                          size=(-1, -1), pos=(150, 50),
                                          style=wx.ALIGN_CENTER)
              self.FtoE = wx.Button(self.win, 101, 'French to English', pos=(150, 100),
                                    size=wx.DefaultSize, style=wx.NO_BORDER)
              self.FtoE.Bind(wx.EVT_BUTTON, self.French)
              self.EtoF = wx.Button(self.win, 201, 'English to French', pos=(150, 150),
                                    size=wx.DefaultSize, style=wx.NO_BORDER)
              self.EtoF.Bind(wx.EVT_BUTTON, self.English)
       
      #MainWinCtrls
              self.Words_Left = wx.StaticText(self.win, -1, 'Welcome',
                                          size=(250, 15), pos=(125, 40),
                                          style=wx.ALIGN_CENTER | wx.ST_NO_AUTORESIZE)
       
              self.Correct_Incorrect = wx.StaticText(self.win,
                                            -1,
                                            '',
                                            pos=(50, 100),
                                            size=(400, 30),
                                            style=wx.ST_NO_AUTORESIZE |
                                            wx.ALIGN_CENTRE)
       
              self.Word_Correction = wx.StaticText(self.win,
                                            -1,
                                            '',
                                            pos=(50, 150),
                                            size=(400, 80),
                                            style=wx.ST_NO_AUTORESIZE |
                                            wx.ALIGN_CENTRE)
              self.Question = wx.StaticText(self.win,
                                            -1,
                                            '',
                                            pos=(50, 230),
                                            size=(400, 50),
                                            style=wx.ST_NO_AUTORESIZE |
                                            wx.ALIGN_CENTER)
              self.Promt_OnOff = wx.StaticText(self.win,
                                            -1,
                                            'The aswer is?',
                                            pos=(50, 310),
                                            size=(400, 15),
                                            style=wx.ST_NO_AUTORESIZE |
                                            wx.ALIGN_CENTRE)
       
              self.TCinput = wx.TextCtrl(self.win, 1992, '', size=(200, -1),
                                         pos=(150, 350), style=wx.TE_PROCESS_ENTER)
              self.win.Bind(wx.EVT_TEXT_ENTER, self.CheckAnswer, self.TCinput)
          #Custom text buttons
              self.Button_A_Right = wx.Button(self.win, -1, 'À', pos=(10, 10), size=(20, 20))
              self.Button_A_Middle = wx.Button(self.win, -1, 'Â', pos=(30, 10), size=(20, 20))
              self.Button_C_Down = wx.Button(self.win, -1, 'Ç', pos=(50, 10), size=(20, 20))
              self.Button_E_Left = wx.Button(self.win, -1, 'É', pos=(70, 10), size=(20, 20))
              self.Button_E_Right = wx.Button(self.win, -1, 'È', pos=(90, 10), size=(20, 20))
              self.Button_E_Middle = wx.Button(self.win, -1, 'Ê', pos=(110, 10), size=(20, 20))
              self.Button_E_TwoDots = wx.Button(self.win, -1, 'Ë', pos=(130, 10), size=(20, 20))
              self.Button_I_Middle = wx.Button(self.win, -1, 'Î', pos=(150, 10), size=(20, 20))
              self.Button_I_TwoDots = wx.Button(self.win, -1, 'Ï', pos=(170, 10), size=(20, 20))
              self.Button_OE_Combined = wx.Button(self.win, -1, 'Œ', pos=(190, 10), size=(20, 20))
              self.Button_O_Middle = wx.Button(self.win, -1, 'Ô', pos=(210, 10), size=(20, 20))
              self.Button_U_Right = wx.Button(self.win, -1, 'Ù', pos=(230, 10), size=(20, 20))
              self.Button_U_Middle = wx.Button(self.win, -1, 'Û', pos=(250, 10), size=(20, 20))
              Buttons = [[self.Button_A_Right, 'À'], [self.Button_A_Middle, 'Â'],
                         [self.Button_C_Down, 'Ç'], [self.Button_E_Left, 'É'],
                         [self.Button_E_Right, 'È'], [self.Button_E_Middle, 'Ê'],
                         [self.Button_E_TwoDots, 'Ë'], [self.Button_I_Middle, 'Î'],
                         [self.Button_I_TwoDots, 'Ï'], [self.Button_OE_Combined, 'Œ'],
                         [self.Button_O_Middle, 'Ô'], [self.Button_U_Right, 'Ù'],
                         [self.Button_U_Middle, 'Û']]
              for Button in Buttons:
                  Button[0].Bind(wx.EVT_BUTTON, self.Button_SpCar)
              self.Button_A_Right.Bind(wx.EVT_BUTTON, self.Button_SpCar)
          #SetColors
              self.Words_Left.SetForegroundColour('Red')
              self.Words_Left.SetBackgroundColour('')
              self.Correct_Incorrect.SetForegroundColour('Red')
              self.Correct_Incorrect.SetBackgroundColour('')
              self.Word_Correction.SetForegroundColour('Red')
              self.Word_Correction.SetBackgroundColour('')
              self.Question.SetForegroundColour('Red')
              self.Question.SetBackgroundColour('')
              self.Promt_OnOff.SetForegroundColour('Red')
              self.Promt_OnOff.SetBackgroundColour('')
              self.TCinput.SetBackgroundColour('Yellow')
              self.TCinput.SetForegroundColour('Red')
              #dissable devices
              self.Words_Left.Show(False)
              self.Correct_Incorrect.Show(False)
              self.Word_Correction.Show(False)
              self.Question.Show(False)
              self.Promt_OnOff.Show(False)
              self.TCinput.Show(False)
      #MainWinMenuBar
              MenuBar = wx.MenuBar()
              #Menu1
              Menu1 = wx.Menu()
              Menu1.Append(101, 'Restart\tF1', 'Restarts the program')
              Menu1.Append(102, 'Add\tCtrl+A', 'Open the Add window')
              Menu1.Append(103, 'Close', 'Close French quiz')
              MenuBar.Append(Menu1, '&Game')
              #SetMenuBar
              self.win.SetMenuBar(MenuBar)
              #MenuEvents
              self.win.Bind(wx.EVT_MENU, self.Restart, id=101)
              self.win.Bind(wx.EVT_MENU, self.OpenAddWin, id=102)
              self.win.Bind(wx.EVT_MENU, self.Close, id=103)
      #Start main loop
              self.app.MainLoop()
       
          #Asign values...
              self.Words_Left.SetLabel('You have ' + str(self.wordsleft) +
                                       ' words left')
              self.Question.SetLabel('The next question is\n\n' + word)
       
          #Methods
          def GameLoop(self, evt):
              self.TCinput.SetFocus()
              try:
                  x = self.wordsleft
              except:
                  #print self.AllWords##############
                  self.French = self.AllWords[0]['French']
                  self.English = self.AllWords[0]['English']
                  self.wordsleft = 0
                  self.correct_incorrect = ''
                  self.word_correction = ''
       
              self.wordsleft = len(self.French)
              self.word_number = ran(len(self.French))
              if self.language == 'French':
                  word = self.French[self.word_number]
                  self.correct_answer = self.English[self.word_number]
              elif self.language == 'English':
                  word = self.English[self.word_number]
                  self.correct_answer = self.French[self.word_number]
              self.Words_Left.SetLabel('You have ' + str(self.wordsleft) +
                                       ' words left')
              self.Question.SetLabel('The next question is\n\n' + word)
       
          def CheckAnswer(self, evt):
              if self.TCinput.GetValue():
                  if self.TCinput.GetValue().upper() == self.correct_answer:
                      self.correct_incorrect = 'Correct'
                      del self.French[self.word_number]
                      del self.English[self.word_number]
                      self.Word_Correction.SetLabel('')
                  else:
                      self.correct_incorrect = 'Incorrect'
                      self.Word_Correction.SetLabel('The correct answer was:\n' +
                                                    self.correct_answer)
              self.Correct_Incorrect.SetLabel(self.correct_incorrect)
              self.TCinput.SetValue('')
              if len(self.French) == 0:
                          self.Score(evt)
              else:
                  self.GameLoop(evt)
          def Score(self, evt):
              pass
              #################################################################
              #################################################################
              #################################################################
              #################################################################
              #################################################################
              ###################   Fill in text here   #######################
              #################################################################
              #################################################################
              #################################################################
              #################################################################
              #################################################################
       
          def show(self, mainwin=False, secoundwin=False):
              self.FtoE.Show(mainwin)
              self.EtoF.Show(mainwin)
       
              self.Words_Left.Show(secoundwin)
              self.Correct_Incorrect.Show(secoundwin)
              self.Word_Correction.Show(secoundwin)
              self.Question.Show(secoundwin)
              self.Promt_OnOff.Show(secoundwin)
              self.TCinput.Show(secoundwin)
          def Button_SpCar(self, evt):
              text = self.TCinput.GetValue()
              self.TCinput.SetValue(
                  text + evt.GetEventObject().GetLabel())
              self.TCinput.SetFocus()
              self.TCinput.XYToPosition(0, (len(text + 1)))
       
          def French(self, evt):
              self.language = 'French'
              self.show(secoundwin=True)
              self.GameLoop(evt)
       
          def English(self, evt):
              self.language = 'English'
              self.show(secoundwin=True)
              self.GameLoop(evt)
       
          def Close(self, evt):
              self.win.Close()
          def Restart(self, evt):
              self.wordsleft = 0
              self.show(mainwin=True)
          def AddWords(self, evt):
                  if self.TC_French:
                      if self.TC_English:
       
                          self.AddWin_WordListFR.append(self.TC_French.GetValue().strip())
                          self.AddWin_WordListEN.append(self.TC_English.GetValue().strip())
                          x_FR = 0
                          for i in range(len(self.AddWin_WordListFR)):
                              y = len(self.AddWin_WordListFR[i])
                              if x_FR > y:
                                  x_FR = y
                          List = ''
                          for i in range(len(self.AddWin_WordListFR)):
                              List += self.AddWin_WordListFR[i] + ' '*(0
                                  #x_FR - len(self.AddWin_WordListFR[i])
                                  + 6) + self.AddWin_WordListEN[i] + '\n  '
                          self.TC_WordList.SetValue(
                              ' '*2 + 'French words:' + ' '*(x_FR - 13) + ' '*6 + 'English words:\n' + ' '*2 + List)
                          self.TC_French.SetValue('')
                          self.TC_English.SetValue('')
                          self.TC_French.SetFocus()
                  else:
                      self.dlg.Show()
                      self.TC_French.SetFocus()
          def OpenAddWin(self, evt):
              self.AddWin_WordListFR = []
              self.AddWin_WordListEN = []
              #Functions
              def next(evt):
                  self.TC_English.SetFocus()
       
              def AddWin_Button_Cancel(evt):
                  self.AddWin.Close()
              def AddWin_Button_Edit(evt):
                  #Functions
                  def EditWin_Button_Cancel(evt):
                      EditWin.Close()
                  def EditWin_Button_Ok(evt):
                      self.AddWin_WordListFR = []
                      for i in range(self.TCEditFR.GetNumberOfLines()):
                          if len(self.TCEditFR.GetValue().strip()) > 0:
                              self.AddWin_WordListFR.append(self.TCEditFR.GetLineText(i).strip())
                      self.AddWin_WordListEN = []
                      for i in range(self.TCEditEN.GetNumberOfLines()):
                          if len(self.TCEditEN.GetValue().strip()) > 0:
                              self.AddWin_WordListEN.append(self.TCEditEN.GetLineText(i).strip())
                      EditWin.Close()
                      self.AddWords(evt)
       
                  EditWin = wx.Frame(self.AddWin,
                                     title='Edit Window',
                                     size=(600, 400),
                                     pos=(300, 300),
                                     style=wx.CLOSE_BOX |
                                     wx.CAPTION |
                                     wx.FRAME_NO_TASKBAR |
                                     wx.SYSTEM_MENU)
                  EditWin.Show()
                  self.TCEditFR = wx.TextCtrl(EditWin, -1, '', size=(280, 310),
                                              pos=(10, 20), style=wx.TE_MULTILINE |
                                              wx.TE_DONTWRAP)
                  self.TCEditEN = wx.TextCtrl(EditWin, -1, '', size=(280, 310),
                                              pos=(300, 20), style=wx.TE_MULTILINE |
                                              wx.TE_DONTWRAP)
                  EditWin_Cancel = wx.Button(EditWin, -1, 'Cancel', size=(100, 20),
                                             pos=(105, 340))
                  EditWin_Cancel.Bind(wx.EVT_BUTTON, EditWin_Button_Cancel)
                  EditWin_Ok = wx.Button(EditWin, -1, 'Ok', size=(100, 20),
                                         pos=(395, 340))
                  EditWin_Ok.Bind(wx.EVT_BUTTON, EditWin_Button_Ok)
                  #Append data
                  string = ''
                  for i in range(len(self.AddWin_WordListFR)):
                      string += self.AddWin_WordListFR[i] + '\n'
                  self.TCEditFR.SetValue(string)
                  string = ''
                  for i in range(len(self.AddWin_WordListEN)):
                      string += self.AddWin_WordListEN[i] + '\n'
                  self.TCEditEN.SetValue(string)
              def AddWin_Button_Confirm(evt):
                  dlg = wx.FileDialog(self.AddWin, message='Save file as ...',
                                      wildcard='Text Document', style=wx.SAVE)
                  if dlg.ShowModal() == wx.ID_OK:
                      path = dlg.GetPath()
                      fp = file(path, 'w')
                      words = []
                      for word in self.AddWin_WordListFR:
                          words += word + '\n'
                      fp.writelines(words)
                      fp.write('#english#\n')
                      words = []
                      for word in self.AddWin_WordListEN:
                          words += word + '\n'
                      fp.writelines(words)
                      fp.close
                      #self.saveinfo['DefaultSavePath'] = path
       
                  #when opening txt files use a for loop and get rid of all the \n (newlines) by
                  #use:  if str[-2:] == '\n':
                  #          str = str[0:-2]
                  #and the oposite for when your saving files
                  #
                  #
                  #
                  #use filedialow to save and to open
                  pass
       
       
       
              self.AddWin = wx.Frame(self.win,
                              title='Add Window',
                              size=(400, 500),
                              pos=(300, 300),
                              style=wx.CLOSE_BOX |
                              wx.CAPTION |
                              wx.FRAME_NO_TASKBAR |
                              wx.SYSTEM_MENU)
              self.AddWin.Show()
              #French
              Static_French = wx.StaticText(self.AddWin, -1,
                                             'French word or phrase:', pos=(7, 10))
              self.TC_French = wx.TextCtrl(self.AddWin, -1, '', size=(380, 20),
                                            pos=(7, 25))
              self.TC_French.Bind(wx.EVT_TEXT_ENTER
      , next)
              self.TC_French.SetFocus()
              #English
              Static_English = wx.StaticText(self.AddWin, -1,
                                             'English word or phrase:', pos=(7, 50))
              self.TC_English = wx.TextCtrl(self.AddWin, -1, '', size=(380, 20),
                                            pos=(7, 65), style=wx.TE_PROCESS_ENTER)
              self.TC_English.Bind(wx.EVT_TEXT_ENTER, self.AddWords)
              #WordList
              Static_WordList = wx.StaticText(self.AddWin, -1,
                                              'Check list to confirm accuracy:',
                                              pos=(7, 95))
              self.TC_WordList = wx.TextCtrl(self.AddWin, -1, '', size=(380, 310),
                                             pos=(7, 110), style=wx.TE_MULTILINE | wx.TE_DONTWRAP)
              #Cancel
              self.AddWin_Cancel = wx.Button(self.AddWin, -1, 'Cancel', size=(100, 20),
                                              pos=(7, 440))
              self.AddWin_Cancel.Bind(wx.EVT_BUTTON, AddWin_Button_Cancel)
              #Edit
              self.AddWin_Edit = wx.Button(self.AddWin, -1, 'Edit', size=(100, 20),
                                            pos=(135, 440))
              self.AddWin_Edit.Bind(wx.EVT_BUTTON, AddWin_Button_Edit)
              #Confirm
              self.AddWin_Confirm = wx.Button(self.AddWin, -1, 'Confirm', size=(100, 20),
                                               pos=(263, 440))
              self.AddWin_Confirm.Bind(wx.EVT_BUTTON, AddWin_Button_Confirm)
       
       
      if __name__ == '__main__':
          win = FrenchQuiz()
          win.start()

      Comment

      • kaarthikeyapreyan
        New Member
        • Apr 2007
        • 106

        #4
        Gurus, correct me if am wrong :)

        Code:
                self.app.MainLoop()
         
            #Asign values...
                self.Words_Left.SetLabel('You have ' + str(self.wordsleft) +' words left')
                self.Question.SetLabel('The next question is\n\n' + word)
        Try moving the last two lines of the code above the MainLoop
        I think the error occurs because when the instance of the main frame is destroyed all the widgets associated are also destroyed but the last two lines perform some activity after the instance of the attribute is destroyed.

        I read some where on the net that the objects in the frame are destroyed after being Queued up so i guess all the child widgets fall in place before the mainframe, do not manipulate it after the MainLoop

        Comment

        • josh001
          New Member
          • Jul 2008
          • 19

          #5
          Solved!

          Solved!
          The error message doesn't pop up anymore, Thanks.

          The only thing left now is that when I try to open the program without Python Shell (just by clicking on the icon) it doesn't do a thing.
          I've saved the file as *.pyw and don't have any idea why it's not opening.

          Hear is the slightly edited code.

          Code:
           
          import wx, shelve, os
          from random import randrange as ran
          from pprint import pprint 
          class FrenchQuiz:
              def start(self):
                  self.app = wx.App()
                  #Define all windows
                  self.win = wx.Frame(None,
                                      title='French Quiz',
                                      size=(500, 500,),
                                      pos=(400, 250),
                                      style=wx.CLOSE_BOX | wx.CAPTION | wx.SYSTEM_MENU)
                  self.win.SetBackgroundColour('Black')
                  self.win.Show()
           
                  OpenDLG = wx.FileDialog(
                      self.win,
                      message='Please choose the quiz or quizes that you wish to use.',
                      defaultDir=os.getcwd(),
                      defaultFile='',
                      wildcard='*.*',
                      style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR)
                  self.AllWords = {}
                  wordlistnum = -1
                  if OpenDLG.ShowModal() == wx.ID_OK:
                      paths = OpenDLG.GetPaths()
                      for path in paths:
                          textfile = open(path)
                          words = textfile.readlines()
                          french = []
                          english = []
                          Pass = 'no'
                          wordlistnum +=1
                          for word in words:
                              if Pass == 'yes':
                                  english.append(word[0:-2])
                              if '#english#' in word:
                                  Pass = 'yes'
                              if Pass == 'no':
                                  if '#english#' not in word:
                                      french.append(word[0:-2])
                          self.AllWords.update(
                              {wordlistnum: {'French': french, 'English': english}})
           
                  self.win.Show()
          #MainWinStatusBar
                  self.win.CreateStatusBar()
                  self.win.SetStatusText('Hello')
          #MainWinStartUp
                  self.Prompt = wx.StaticText(self.win, -1,
                                              'Please choose one of the folowing',
                                              size=(-1, -1), pos=(150, 50),
                                              style=wx.ALIGN_CENTER)
                  self.FtoE = wx.Button(self.win, 101, 'French to English', pos=(150, 100),
                                        size=wx.DefaultSize, style=wx.NO_BORDER)
                  self.FtoE.Bind(wx.EVT_BUTTON, self.French)
                  self.EtoF = wx.Button(self.win, 201, 'English to French', pos=(150, 150),
                                        size=wx.DefaultSize, style=wx.NO_BORDER)
                  self.EtoF.Bind(wx.EVT_BUTTON, self.English)
           
          #MainWinCtrls
                  self.Words_Left = wx.StaticText(self.win, -1, 'Welcome',
                                              size=(250, 15), pos=(125, 40),
                                              style=wx.ALIGN_CENTER | wx.ST_NO_AUTORESIZE)
           
                  self.Correct_Incorrect = wx.StaticText(self.win,
                                                -1,
                                                '',
                                                pos=(50, 100),
                                                size=(400, 30),
                                                style=wx.ST_NO_AUTORESIZE |
                                                wx.ALIGN_CENTRE)
           
                  self.Word_Correction = wx.StaticText(self.win,
                                                -1,
                                                '',
                                                pos=(50, 150),
                                                size=(400, 80),
                                                style=wx.ST_NO_AUTORESIZE |
                                                wx.ALIGN_CENTRE)
                  self.Question = wx.StaticText(self.win,
                                                -1,
                                                '',
                                                pos=(50, 230),
                                                size=(400, 50),
                                                style=wx.ST_NO_AUTORESIZE |
                                                wx.ALIGN_CENTER)
                  self.Promt_OnOff = wx.StaticText(self.win,
                                                -1,
                                                'The aswer is?',
                                                pos=(50, 310),
                                                size=(400, 15),
                                                style=wx.ST_NO_AUTORESIZE |
                                                wx.ALIGN_CENTRE)
           
                  self.TCinput = wx.TextCtrl(self.win, 1992, '', size=(200, -1),
                                             pos=(150, 350), style=wx.TE_PROCESS_ENTER)
                  self.win.Bind(wx.EVT_TEXT_ENTER, self.CheckAnswer, self.TCinput)
              #Custom text buttons
                  self.Button_A_Right = wx.Button(self.win, -1, 'À', pos=(10, 10), size=(20, 20))
                  self.Button_A_Middle = wx.Button(self.win, -1, 'Â', pos=(30, 10), size=(20, 20))
                  self.Button_C_Down = wx.Button(self.win, -1, 'Ç', pos=(50, 10), size=(20, 20))
                  self.Button_E_Left = wx.Button(self.win, -1, 'É', pos=(70, 10), size=(20, 20))
                  self.Button_E_Right = wx.Button(self.win, -1, 'È', pos=(90, 10), size=(20, 20))
                  self.Button_E_Middle = wx.Button(self.win, -1, 'Ê', pos=(110, 10), size=(20, 20))
                  self.Button_E_TwoDots = wx.Button(self.win, -1, 'Ë', pos=(130, 10), size=(20, 20))
                  self.Button_I_Middle = wx.Button(self.win, -1, 'Î', pos=(150, 10), size=(20, 20))
                  self.Button_I_TwoDots = wx.Button(self.win, -1, 'Ï', pos=(170, 10), size=(20, 20))
                  self.Button_OE_Combined = wx.Button(self.win, -1, 'Œ', pos=(190, 10), size=(20, 20))
                  self.Button_O_Middle = wx.Button(self.win, -1, 'Ô', pos=(210, 10), size=(20, 20))
                  self.Button_U_Right = wx.Button(self.win, -1, 'Ù', pos=(230, 10), size=(20, 20))
                  self.Button_U_Middle = wx.Button(self.win, -1, 'Û', pos=(250, 10), size=(20, 20))
                  Buttons = [[self.Button_A_Right, 'À'], [self.Button_A_Middle, 'Â'],
                             [self.Button_C_Down, 'Ç'], [self.Button_E_Left, 'É'],
                             [self.Button_E_Right, 'È'], [self.Button_E_Middle, 'Ê'],
                             [self.Button_E_TwoDots, 'Ë'], [self.Button_I_Middle, 'Î'],
                             [self.Button_I_TwoDots, 'Ï'], [self.Button_OE_Combined, 'Œ'],
                             [self.Button_O_Middle, 'Ô'], [self.Button_U_Right, 'Ù'],
                             [self.Button_U_Middle, 'Û']]
                  for Button in Buttons:
                      Button[0].Bind(wx.EVT_BUTTON, self.Button_SpCar)
                  self.Button_A_Right.Bind(wx.EVT_BUTTON, self.Button_SpCar)
              #SetColors
                  self.Words_Left.SetForegroundColour('Red')
                  self.Words_Left.SetBackgroundColour('')
                  self.Correct_Incorrect.SetForegroundColour('Red')
                  self.Correct_Incorrect.SetBackgroundColour('')
                  self.Word_Correction.SetForegroundColour('Red')
                  self.Word_Correction.SetBackgroundColour('')
                  self.Question.SetForegroundColour('Red')
                  self.Question.SetBackgroundColour('')
                  self.Promt_OnOff.SetForegroundColour('Red')
                  self.Promt_OnOff.SetBackgroundColour('')
                  self.TCinput.SetBackgroundColour('Yellow')
                  self.TCinput.SetForegroundColour('Red')
                  #dissable devices
                  self.Words_Left.Show(False)
                  self.Correct_Incorrect.Show(False)
                  self.Word_Correction.Show(False)
                  self.Question.Show(False)
                  self.Promt_OnOff.Show(False)
                  self.TCinput.Show(False)
          #MainWinMenuBar
                  MenuBar = wx.MenuBar()
                  #Menu1
                  Menu1 = wx.Menu()
                  Menu1.Append(101, 'Restart\tF1', 'Restarts the program')
                  Menu1.Append(102, 'Add\tCtrl+A', 'Open the Add window')
                  Menu1.Append(103, 'Close', 'Close French quiz')
                  MenuBar.Append(Menu1, '&Game')
                  #SetMenuBar
                  self.win.SetMenuBar(MenuBar)
                  #MenuEvents
                  self.win.Bind(wx.EVT_MENU, self.Restart, id=101)
                  self.win.Bind(wx.EVT_MENU, self.OpenAddWin, id=102)
                  self.win.Bind(wx.EVT_MENU, self.Close, id=103)
           
          #Start main loop
                  self.app.MainLoop()
           
              #Methods
              def GameLoop(self, evt):
                  self.TCinput.SetFocus()
                  try:
                      x = self.wordsleft
                  except:
                      self.French = self.AllWords[0]['French']
                      self.English = self.AllWords[0]['English']
                      self.wordsleft = 0
                      self.correct_incorrect = ''
                      self.word_correction = ''
           
                  self.wordsleft = len(self.French)
                  self.word_number = ran(len(self.French))
                  if self.language == 'French':
                      word = self.French[self.word_number]
                      self.correct_answer = self.English[self.word_number]
                  elif self.language == 'English':
                      word = self.English[self.word_number]
                      self.correct_answer = self.French[self.word_number]
                  self.Words_Left.SetLabel('You have ' + str(self.wordsleft) +
                                           ' words left')
                  self.Question.SetLabel('The next question is\n\n' + word)
           
              def CheckAnswer(self, evt):
                  if self.TCinput.GetValue():
                      if self.TCinput.GetValue().upper() == self.correct_answer:
                          self.correct_incorrect = 'Correct'
                          del self.French[self.word_number]
                          del self.English[self.word_number]
                          self.Word_Correction.SetLabel('')
                      else:
                          self.correct_incorrect = 'Incorrect'
                          self.Word_Correction.SetLabel('The correct answer was:\n' +
                                                        self.correct_answer)
                  self.Correct_Incorrect.SetLabel(self.correct_incorrect)
                  self.TCinput.SetValue('')
                  if len(self.French) == 0:
                              self.Score(evt)
                  else:
                      self.GameLoop(evt)
              def Score(self, evt):
                  pass
                  #################################################################
                  #################################################################
                  #################################################################
                  #################################################################
                  #################################################################
                  ###################   Fill in text here   #######################
                  #################################################################
                  #################################################################
                  #################################################################
                  #################################################################
                  #################################################################
           
              def show(self, mainwin=False, secoundwin=False):
                  self.FtoE.Show(mainwin)
                  self.EtoF.Show(mainwin)
           
                  self.Words_Left.Show(secoundwin)
                  self.Correct_Incorrect.Show(secoundwin)
                  self.Word_Correction.Show(secoundwin)
                  self.Question.Show(secoundwin)
                  self.Promt_OnOff.Show(secoundwin)
                  self.TCinput.Show(secoundwin)
              def Button_SpCar(self, evt):
                  text = self.TCinput.GetValue()
                  self.TCinput.SetValue(
                      text + evt.GetEventObject().GetLabel())
                  self.TCinput.SetFocus()
                  self.TCinput.XYToPosition(0, (len(text + 1)))
           
              def French(self, evt):
                  self.language = 'French'
                  self.show(secoundwin=True)
                  self.GameLoop(evt)
           
              def English(self, evt):
                  self.language = 'English'
                  self.show(secoundwin=True)
                  self.GameLoop(evt)
           
              def Close(self, evt):
                  self.win.Close()
              def Restart(self, evt):
                  self.wordsleft = 0
                  self.show(mainwin=True)
              def AddWords(self, evt):
                      if self.TC_French:
                          if self.TC_English:
           
                              self.AddWin_WordListFR.append(self.TC_French.GetValue().strip())
                              self.AddWin_WordListEN.append(self.TC_English.GetValue().strip())
                              x_FR = 0
                              for i in range(len(self.AddWin_WordListFR)):
                                  y = len(self.AddWin_WordListFR[i])
                                  if x_FR > y:
                                      x_FR = y
                              List = ''
                              for i in range(len(self.AddWin_WordListFR)):
                                  List += self.AddWin_WordListFR[i] + ' '*(0
                                      #x_FR - len(self.AddWin_WordListFR[i])
                                      + 6) + self.AddWin_WordListEN[i] + '\n  '
                              self.TC_WordList.SetValue(
                                  ' '*2 + 'French words:' + ' '*(x_FR - 13) + ' '*6 + 'English words:\n' + ' '*2 + List)
                              self.TC_French.SetValue('')
                              self.TC_English.SetValue('')
                              self.TC_French.SetFocus()
                      else:
                          self.dlg.Show()
                          self.TC_French.SetFocus()
              def OpenAddWin(self, evt):
                  self.AddWin_WordListFR = []
                  self.AddWin_WordListEN = []
                  #Functions
                  def next(evt):
                      self.TC_English.SetFocus()
           
                  def AddWin_Button_Cancel(evt):
                      self.AddWin.Close()
                  def AddWin_Button_Edit(evt):
                      #Functions
                      def EditWin_Button_Cancel(evt):
                          EditWin.Close()
                      def EditWin_Button_Ok(evt):
                          self.AddWin_WordListFR = []
                          for i in range(self.TCEditFR.GetNumberOfLines()):
                              if len(self.TCEditFR.GetValue().strip()) > 0:
                                  self.AddWin_WordListFR.append(self.TCEditFR.GetLineText(i).strip())
                          self.AddWin_WordListEN = []
                          for i in range(self.TCEditEN.GetNumberOfLines()):
                              if len(self.TCEditEN.GetValue().strip()) > 0:
                                  self.AddWin_WordListEN.append(self.TCEditEN.GetLineText(i).strip())
                          EditWin.Close()
                          self.AddWords(evt)
           
                      EditWin = wx.Frame(self.AddWin,
                                         title='Edit Window',
                                         size=(600, 400),
                                         pos=(300, 300),
                                         style=wx.CLOSE_BOX |
                                         wx.CAPTION |
                                         wx.FRAME_NO_TASKBAR |
                                         wx.SYSTEM_MENU)
                      EditWin.Show()
                      self.TCEditFR = wx.TextCtrl(EditWin, -1, '', size=(280, 310),
                                                  pos=(10, 20), style=wx.TE_MULTILINE |
                                                  wx.TE_DONTWRAP)
                      self.TCEditEN = wx.TextCtrl(EditWin, -1, '', size=(280, 310),
                                                  pos=(300, 20), style=wx.TE_MULTILINE |
                                                  wx.TE_DONTWRAP)
                      EditWin_Cancel = wx.Button(EditWin, -1, 'Cancel', size=(100, 20),
                                                 pos=(105, 340))
                      EditWin_Cancel.Bind(wx.EVT_BUTTON, EditWin_Button_Cancel)
                      EditWin_Ok = wx.Button(EditWin, -1, 'Ok', size=(100, 20),
                                             pos=(395, 340))
                      EditWin_Ok.Bind(wx.EVT_BUTTON, EditWin_Button_Ok)
                      #Append data
                      string = ''
                      for i in range(len(self.AddWin_WordListFR)):
                          string += self.AddWin_WordListFR[i] + '\n'
                      self.TCEditFR.SetValue(string)
                      string = ''
                      for i in range(len(self.AddWin_WordListEN)):
                          string += self.AddWin_WordListEN[i] + '\n'
                      self.TCEditEN.SetValue(string)
                  def AddWin_Button_Confirm(evt):
                      dlg = wx.FileDialog(self.AddWin, message='Save file as ...',
                                          wildcard='Text Document', style=wx.SAVE)
                      if dlg.ShowModal() == wx.ID_OK:
                          path = dlg.GetPath()
                          fp = file(path, 'w')
                          words = []
                          for word in self.AddWin_WordListFR:
                              words += word + '\n'
                          fp.writelines(words)
                          fp.write('#english#\n')
                          words = []
                          for word in self.AddWin_WordListEN:
                              words += word + '\n'
                          fp.writelines(words)
                          fp.close
                          #self.saveinfo['DefaultSavePath'] = path
           
                      #when opening txt files use a for loop and get rid of all the \n (newlines) by
                      #use:  if str[-2:] == '\n':
                      #          str = str[0:-2]
                      #and the oposite for when your saving files
                      #
                      #
                      #
                      #use filedialow to save and to open
                      pass
           
           
           
                  self.AddWin = wx.Frame(self.win,
                                  title='Add Window',
                                  size=(400, 500),
                                  pos=(300, 300),
                                  style=wx.CLOSE_BOX |
                                  wx.CAPTION |
                                  wx.FRAME_NO_TASKBAR |
                                  wx.SYSTEM_MENU)
                  self.AddWin.Show()
                  #French
                  Static_French = wx.StaticText(self.AddWin, -1,
                                                 'French word or phrase:', pos=(7, 10))
                  self.TC_French = wx.TextCtrl(self.AddWin, -1, '', size=(380, 20),
                                                pos=(7, 25))
                  self.TC_French.Bind(wx.EVT_TEXT_ENTER
          , next)
                  self.TC_French.SetFocus()
                  #English
                  Static_English = wx.StaticText(self.AddWin, -1,
                                                 'English word or phrase:', pos=(7, 50))
                  self.TC_English = wx.TextCtrl(self.AddWin, -1, '', size=(380, 20),
                                                pos=(7, 65), style=wx.TE_PROCESS_ENTER)
                  self.TC_English.Bind(wx.EVT_TEXT_ENTER, self.AddWords)
                  #WordList
                  Static_WordList = wx.StaticText(self.AddWin, -1,
                                                  'Check list to confirm accuracy:',
                                                  pos=(7, 95))
                  self.TC_WordList = wx.TextCtrl(self.AddWin, -1, '', size=(380, 310),
                                                 pos=(7, 110), style=wx.TE_MULTILINE | wx.TE_DONTWRAP)
                  #Cancel
                  self.AddWin_Cancel = wx.Button(self.AddWin, -1, 'Cancel', size=(100, 20),
                                                  pos=(7, 440))
                  self.AddWin_Cancel.Bind(wx.EVT_BUTTON, AddWin_Button_Cancel)
                  #Edit
                  self.AddWin_Edit = wx.Button(self.AddWin, -1, 'Edit', size=(100, 20),
                                                pos=(135, 440))
                  self.AddWin_Edit.Bind(wx.EVT_BUTTON, AddWin_Button_Edit)
                  #Confirm
                  self.AddWin_Confirm = wx.Button(self.AddWin, -1, 'Confirm', size=(100, 20),
                                                   pos=(263, 440))
                  self.AddWin_Confirm.Bind(wx.EVT_BUTTON, AddWin_Button_Confirm)
           
           
          if __name__ == '__main__':
              win = FrenchQuiz()
              win.start()

          Comment

          • boxfish
            Recognized Expert Contributor
            • Mar 2008
            • 469

            #6
            Unfortunately, I can't test your program because I don't have wx. Does it work as a .py file? Is the .pyw file being opened with pythonw.exe?

            Comment

            Working...