This is a Chemistry Quiz and i created the QUESTIONSTARTER class as an object. I am trying to access the widgets from that class and place it in the STAGE1 Class so i can grid them but on the window nothing shows up on those frames so I don't know what to do. (I also want to access tk widgets from button data too which is another class but i cant show it due to space)
class QUESTIONSTARTER(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
self.Attmepts = 3
self.Points = 0
self.NumberOfTimesSubmitBeenPressed = 0
self.WordedQuestion = tk.Label(self)
self.PointsLabel = tk.Label(self,text = self.Points)
self.AttemptsDisplayed = tk.Button(self, text = self.Attempts)
self.AttemptsDisplayedText = tk.Label(self, text = "Attempts Displayed: ")
def SetQuestionIntro(self):
WordedQuestion.config(text = "Many different organic compounds are synthesised by various routes but they may need specific type of reagents and conditions.")
def SubmitClicked(self, Attempts):
if self.Attempts == 1:
NumberOfTimesSubmitBeenPressed += 1
elif self.Attempts == 2:
NumberOfTimesSubmitBeenPressed += 2
elif self.Attempts == 3:
NumberOfTimesSubmitBeenPressed += 2
if NumberOfTimesSubmitBeenPressed == 3:
controller.show_frame(F)
else:
print ("There was an Error")
#call at random the specific products from product database
#depending on class run
def ButtonPressed(self,ReagentsList):
ReagentsList[0] = CorrectReagent
self.CorrectReagent.configure(bg = 'green')
IncorrectReagentsList = []
IncorrectReagentsList.append(ReagentsList[1])
IncorrectReagentsList.append(ReagentsList[2])
IncorrectReagentsList.append(ReagentsList[3])
for Reagents in IncorrectReagentsList:
tk.Button[Reagents].configure(bg = "red")
ConditionsList[0] = CorrectCondition
self.CorrectCondition.configure(bg = "green")
IncorrectConditionsList = []
IncorrectConditionsList.append(ReagentsList[1])
IncorrectConditionsList.append(ReagentsList[2])
IncorrectConditionsList.append(ReagentsList[3])
for Reagents in IncorrectReagentsList:
tk.Button[Reagents].configure(bg = "red")
def AllocatePointsStage1(self,frames ,ButtonPressed, Attempts, Points):
while self.Attempts == 1:
if self.ReagentOption1.bg == 'green' or self.ConditionOption1.bg == 'green':
self.Points += 20
controller.show_frame(Stage2)
self.frames.remove(Stage2)
self.frames.insert(Stage2)
elif self.ReagentOption2.bg == 'green'or self.ConditionOption2.bg == 'green':
self.Points += 20
self.show_frame(Stage2)
self.frames.remove(Stage2)
self.frames.insert(Stage2)
elif self.ReagentOption3.bg == 'green' or self.ConditionOption3.bg == 'green':
self.Points += 20
self.show_frame(Stage2)
self.frames.remove(Stage2)
self.frames.insert(Stage2)
elif self.ReagentOption4.bg == 'green' or self.ConditionOption4.bg == 'green':
self.Points += 20
self.show_frame(Stage2)
self.frames.remove(Stage2)
self.frames.insert(Stage2)
elif self.ReagentOption1.bg == 'red' or self.ConditionOption1.bg == 'red':
self.Points += 0
self.Attempts += 1
elif self.ReagentOption2.bg == 'red' or self.ConditionOption2.bg == 'red':
self.Points += 0
self.Attempts += 1
elif self.ReagentOption3.bg == 'red' or self.ConditionOption3.bg == 'red':
self.Points += 0
self.Attempts+= 1
elif self.ReagentOption4.bg == 'red' or self.ConditionOption4.bg == 'red':
self.Points += 0
self.Attempts += 1
class STAGE1(tk.Frame):
def __init__(self,parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
Stage1 = tk.Label(self, text = "STAGE 1")
Stage1.grid(column=1,row=0)
#Explain the Main class and tk frame constructor in each class from stack overflow
self.ButtonData = BUTTONDATA(self,tk.Frame)
self.ButtonData.ReagentOption1.config(command=lambda: self.AllocatePointsStage(1))
self.ButtonData.ReagentOption2.config(command=lambda: self.AllocatePointsStage(1))
self.ButtonData.ReagentOption3.config(command=lambda: self.AllocatePointsStage(1))
self.ButtonData.ReagentOption4.config(command=lambda: self.AllocatePointsStage(1))
self.ButtonData.ConditionOption1.config(command=lambda: self.AllocatePointsStage(1))
self.ButtonData.ConditionOption2.config(command=lambda: self.AllocatePointsStage(1))
self.ButtonData.ConditionOption3.config(command=lambda: self.AllocatePointsStage(1))
self.ButtonData.ConditionOption4.config(command=lambda: self.AllocatePointsStage(1))
self.ButtonData.ReagentOption1.grid(column = 2,row = 5)
self.ButtonData.ReagentOption2.grid(column = 2,row = 6)
self.ButtonData.ReagentOption3.grid(column = 2,row = 7)
self.ButtonData.ReagentOption4.grid(column = 2,row = 8)
self.ButtonData.ConditionOption1.grid(column = 10,row = 5)
self.ButtonData.ConditionOption2.grid(column = 10,row = 6)
self.ButtonData.ConditionOption3.grid(column = 10,row = 7)
self.ButtonData.ConditionOption4.grid(column = 10,row = 8)
self.Continue = tk.Button(self, text = "Continue", command=lambda: controller.show_frame(Stage2))
self.Continue.grid(column = 6)
self.QuestionStarter = QUESTIONSTARTER(self,tk.Frame)
self.QuestionStarter.PointsLabel.grid(row=0,column=6)
self.QuestionStarter.AttemptsDisplayed.grid(row=1,column=7)
self.QuestionStarter.WordedQuestion.grid(row=0,column=1)
self.QuestionStarter.AttemptsDisplayedText.grid(row=1,column=8)
DesiredProductLabel = tk.Label(self,command=lambda: ShowDesiredProduct(DesiredProduct))
DesiredProductLabel.grid(row=5,column=0)
def ShowDesiredProduct(self,DesiredProduct):
DesiredProduct = GetDesiredProduct()
return DesiredProduct