Tom Ayling
Tom Ayling

Reputation: 19

Why am I getting this TclError in Python Tkinter

I am having trouble with my tkinter/python work, I am crating a word jumble game for a school project. I keep getting an error message and I have no idea what it means.

This is the code it's self:

fo = open("clues.txt", 'r')
clues = fo.read()
clueList = clues.split(",")

tries = 3

def check_answer(tries, answer, origword, clues):
    global playing
    if answer==origword.strip():
        tk.Label (root, text=("Correct!"), font=("Buxton Sketch", 16)).pack()
        tk.Label (root, text="Do you want to play again?", font=("Buxton Sketch", 16)).pack()
    tk.Button (root, text="Yes", font=("Buxton Sketch", 20), command=lambda: ABC("A")).pack()
    tk.Button (root, text="No", font=("Buxton Sketch", 20), command=lambda: main_menu(ABC)).pack()

def get_guess():
    global answer
    answer = tk.Entry(root, width=40, font=("Buxton Sketch"))

This is the error:

Exception in Tkinter callback
Traceback (most recent call last):
    File "C:\Python34\Assessment Word Jumble\lib\tkinter\__init__.py", line 1533, in __call__
        return self.func(*args)
    File "C:\Python34\Assessment Word Jumble\[email protected]", line74, in <lambda>
        w = tk.Button(root, text="A-Play Word Jumble", command=lambda: ABC("A")).pack()#(row=3, column=1)
    File "C:\Python34\Assessment Word Jumble\[email protected]", line 22, in ABC
        get_guess()
    File "C:\Python34\Assessment Word Jumble\[email protected]", line 63, in get_guess
        answer = tk.Entry (root, width=40, font=("Buxton Sketch"))
    File "C:\Python34\Assessment Word Jumble\lib\tkinter\__init__.py", line 2514, in __init__
        Widget.__init__(self, master, 'entry', cnf, kw)
    File "C:\Python34\Assessment Word Jumble\lib\tkinter\__init__.py", line 2122, in __init__
        (widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: expected integer but got "Sketch"

As I said, I have no idea what any of this means, any help would be greatly appreciated.

Upvotes: 1

Views: 1487

Answers (1)

chown
chown

Reputation: 52728

The font argument of the Entry widget needs to be a tuple('font_name', size) ( size is optional ). Try this:

def get_guess():
    global answer

    # ** Change this **
    # answer = tk.Entry(root, width=40, font= ("Buxton Sketch"))

    # ** To this **
    answer = tk.Entry(root, width=40, font=("Buxton Sketch", 16))

    # ** this will work too **
    answer = tk.Entry(root, width=40, font=("Buxton Sketch",))

Upvotes: 1

Related Questions