Question

I have been experimenting with entry widgets and mapping variables to functions using TTK and python 3.2

I keep getting a syntax error here and can't find it.

from tkinter import *
from tkinter import ttk

def overlap(*args):
    start = begin.get()
    stop = end.get()
    time.set(int(stop)-int(start))

root = Tk()
root.title('RadioButton')

mainframe=ttk.Frame(root, padding='3 3 12 12')
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)

begin = StringVar()
end = StringVar()
time = StringVar()

start_entry = ttk.Entry(mainframe, textvariable = begin)
start_entry.grid(column=1, row=1, sticky=(E, W)

end_entry = ttk.Entry(mainframe, textvariable = end)
end_entry.grid(column=2, row=1, sticky=(E, W)

ttk.Lable(mainframe, textvariable=time).grid(column=1, row=2, sticky=(E, W))

ttk.Button(mainframe, text='calculate', command=overlap).grid(column=1, row=3, sticky=(E, W))

begin_entry.focus()

root.bind('<Return>', overlap)

root.mainloop()

I'm lost, what am I missing? The Error it gives me:

end_entry = ttk.Entry(mainframe, textvariable = end)

SyntaxError: invalid syntax

As I assume you can tell I don't know much about ttk so please try and explain it to me like I'm about 5.

Was it helpful?

Solution

You're missing a closing parenthesis on the line before:

start_entry.grid(column=1, row=1, sticky=(E, W)
#                                              ^
end_entry = ttk.Entry(mainframe, textvariable = end)

As a rule of thumb, if you ever find that you're getting an inexplicable syntax error, make sure that the preceding lines have properly closed parenthesis.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top