I tried making this to have 2 buttons and a prompt, with the buttons being side by side on a grid. However, I notice that when I run the program only the last button is shown, with a blank screen and the button "Add Terms".
I'm not sure why this is happening, my idea is that for some reason the self.clearFrame()
is running even though it's a command parameter.
Thanks
self.root = tk.Tk()
self.root.geometry("500x500")
self.root.title("VocabMaster")
self.prompt = tk.Label(self.root, text = "What would you like to do?", font = ('Arial', 18))
self.prompt.pack(padx = 10, pady = 10)
self.frame = tk.Frame(self.root)
practiceButton = tk.Button(self.frame, text = f"Practice {len(self.currentReviewList)} terms", font = ('Arial, 20'), command=self.startPractice())
practiceButton.grid(row = 0, column=0)
addItems = tk.Button(self.frame, text = "Add Items", font = ('Arial', 20), command= self.addItem())
addItems.grid(row= 0, column= 1)
self.frame.pack()
self.root.mainloop()
def clearFrame(self):
self.prompt.destroy()
for widgets in self.frame.winfo_children():
widgets.destroy()
def startPractice(self):
self.clearFrame()
for item in self.currentReviewList:
prompt = tk.Label(self.root, text = f"Definition of {item.item_name}?")
prompt.pack()
answerBox = tk.Entry(self.root).place(x = 250, y = 100)
answerBox.pack()
answer = answerBox.get()
# Gets the correct answer
# need to move it to next level, display correct, and update it's time.
if answer == item.item_definition:
# Displaying correct
correct = tk.Button(self.root, text = "Correct!", font = ('Arial', 10))
# Fixing level
item.item_level+=1
# Updating time for next review
item = HelperMethods.getNewHoursForItem(item)
correct.pack()
# Gets the wrong answer
else:
# demoting level
item.item_level-=1
# Updating time for next reviwe
item = HelperMethods.getNewHoursForItem(item)
#Displaying definition, as well as informing of incorrect
definitionLabel = tk.Label(self.root, text = f"Wrong! Correct definition is {item.item_definition}")
definitionLabel.pack()
nextButton = tk.Button(self.root, text = "Next", font = ('Arial', 10))
nextButton.pack()
self.clearFrame()
def addItem(self):
self.clearFrame()
term_frame = tk.Frame(self.root)
term_label = tk.Label(term_frame, text = "Please enter the term you would like to add", font = ('Arial', 16))
term_label.grid(row = 0, column=0)
t_entry = tk.Entry(term_frame)
t_entry.grid(row = 0, column=0)
defn_frame = tk.Frame(self.root)
defn_label = tk.Label(defn_frame, text = "Please enter the definition of the term", font = ('Arial', 16))
defn_label.grid
d_entry = tk.Entry(defn_frame)
d_entry.grid(row = 0, column=1)