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. -
-
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
5 1919
Could u post your code so that v can figure out the solution for it.
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. -
-
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()
-
- 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
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. -
-
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()
-
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?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Steve |
last post by:
I just spent waaaaaaaaaaaayy too much time trying to track down an error that was incorrectly reported just now, and I would like to see if someone
can explain to me why it was reported that way.
...
|
by: brazilnut |
last post by:
Hi. Let me explain the setup. I am using Visual Studio .NET to develop a sort of add-in (COM class) for Excel called SQLAddin. It basically queries a SQL server and pulls in data. Now within my...
|
by: Zenobia |
last post by:
Hi,
Below is a bit of code from ASP.NET Unleashed which gives an
error and I can't figure out why. It uses the Authors table from
the standard Pubs database.
The error message is...
|
by: Shawn |
last post by:
JIT Debugging failed with the following error: Access is denied.
JIT Debugging was initiated by the following account 'PLISKEN\ASPNET'
I get this messag in a dialog window when I try to open an...
|
by: dee |
last post by:
Hi
In web.config I have to the following:
<configuration>
<system.web>
<customErrors defaultRedirect="error.htm" mode="On" />
</system.web>
</configuration>
|
by: Rabbit |
last post by:
Dear All,
I've been tried various configuration and did install SP1 on Windows 2003
Server.
The problem now that I have is an aspx page located on the web site for
taking the file post by...
|
by: marklawford |
last post by:
Not having earned my DBA badge from the scouts just yet I'm a little
lost with an error I'm getting.
We've just upgraded our development database from 7.2 to 8.2 as the
first step in upgrading...
|
by: robert d via AccessMonster.com |
last post by:
I have a global error handler that up until today has
been working flawlessly. Let me first provide the relevant code
****************************************************************
On Error...
|
by: kommaraju |
last post by:
iam a starter to db2 & jdbc.i have a servlet program which connects to ibm db2
using jdbc.when i run this using apache tomcat 4.1.34 , it is showing a
error message of HTTP STATUS 500
my jdbc...
|
by: jeffc226 |
last post by:
I'm interested in an idiom for handling errors in functions without
using traditional nested ifs, because I think that can be very awkward
and difficult to maintain, when the number of error checks...
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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:
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...
|
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: 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,...
|
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...
| |