1

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\attempt@wordjumbletkinter.py", 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\attempt@wordjumbletkinter.py", line 22, in ABC
        get_guess()
    File "C:\Python34\Assessment Word Jumble\attempt@wordjumbletkinter.py", 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.

chown
  • 51,908
  • 16
  • 134
  • 170
Tom Ayling
  • 19
  • 2
  • Please cut this down to a [minimal example](http://stackoverflow.com/help/mcve) (getting rid of the redundant, commented-out parts would be a start). Also, you're making [this](http://stackoverflow.com/q/2034576/3001761) classic Tkinter error! – jonrsharpe May 27 '15 at 11:21
  • Did you _copy_ the `tkinter` modules into your working directory? – tobias_k May 27 '15 at 11:22

1 Answers1

1

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",))
chown
  • 51,908
  • 16
  • 134
  • 170
  • So what should I do if I want to use Buxton Sketch as my font? – Tom Ayling May 27 '15 at 11:25
  • Change the code of your get_guess function to what I have in my answer and you should be able to use it. – chown May 27 '15 at 11:27
  • 3
    It's not so much that it's missing the size (the size is optional), but that it incorrectly specified the font in a way that tkinter interpreted "Sketch" as the size. One fix is to add the size, but another is just to add a comma, turning the expression `("Buxton Sketch")` into the tuple `("Button Sketch",)` – Bryan Oakley May 27 '15 at 11:56
  • That is correct; it just needs a tuple and its getting a single string instead, so it splits it and assumes the "Sketch" part is the size which wants an int, not a string. making it a tuple with a comma works just as well. – chown May 27 '15 at 11:59