Python Forum
Help with GUI - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Help with GUI (/thread-2558.html)



Help with GUI - BlazingD4NG3R - Mar-24-2017

Hey so I am learning python and i am doing stuff with tkinter and GUIs. I am trying to make a quiz however there is an error and i dont quite know how to fix it. the error is on line 21 and here is what it says

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\Invate\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1699, in __call__
    return self.func(*args)
  File "C:/Users/Invate/Desktop/Stuff/quiz.py", line 21, in click2
    output.delete(0.0, END)
  File "C:\Users\Invate\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 2673, in delete
    self.tk.call(self._w, 'delete', first, last)
_tkinter.TclError: bad entry index "0.0"

it happens when i run and press the get answers button i made.


from tkinter import *
import random

window = Tk()
window.title("Quiz")

question = ""

def click():
    questions = list(questionslist.keys())
    question = random.choice(questions)
    question1.insert(END, question)

def click1():
    questions = list(questionslist.keys())
    question = random.choice(questions)
    question1.delete(0.0, END)
    question1.insert(END, question)

def click2():
    output.delete(0.0, END)
    try:
        answers = questionslist[question]
    except:
        answers = "There is no entry for this word."
    output.insert(END, answers)


b = "Get Question"
getquestion1 = Button(window, text=b, width=10, command=click1).grid(row=0, column=0, sticky=W)

b2 = "Get Answer"
getquestion1 = Button(window, text=b2, width=10, command=click2).grid(row=3, column=0, sticky=W)

question1 = Text(window, width=40, height=3, wrap=WORD, background="light green")
question1.grid(row=2, column=0, columnspan=2, sticky=W)

output = Entry(window, width=75, bg="light green")
output.grid(row=4, column= 0, sticky=W)

questionslist = {
    'What is 1+1?': "2"
}
window.mainloop()

PLEASE HELP ME I REALLY WANT TO COMPLETE THIS SO I CAN MOVE ON!


RE: Help with GUI - nilamo - Mar-24-2017

0.0 is apparently not a valid index. Try just 0, since floats don't make sense as indexes anyway.


RE: Help with GUI - Larz60+ - Mar-24-2017

This code is messed up.
Start small, you try to do too much too fast.
If you work small portions of the code at a time, you will not have a problem in the end
Obvious problems:
getquestion1 button declared twice you will never see the first one
nothing is in a class, but you are referencing (for example question1) before it is declared.

Suggestion start over. get one thing working and then start with the second.