Syntax Error with Button

Using this code that I copied from a Calendar example, I get a Syntax Error: Invalid Syntax under Button. I tried the same code from other sources with the same result. The Button function works with other examples with no problem. I am at a loss to figure out the cause after spending how many hours doing research on this problem. Can you point me in the right direction? As you can guess, I am a beginner…
Thank you.

Import Required Library

from tkinter import *
from tkcalendar import Calendar

Create Object

root = Tk()

Set geometry

root.geometry(“400x400”)

Add Calendar

cal = Calendar(root, selectmode = ‘day’, year = 2020, month = 5, day = 22)
cal.pack(pady = 20)

def grad_date():
date.config(text = "Selected Date is: " + cal.get_date())

Add Button and Label

Button(root, text=“Get Date”,command=grad_date).pack(pady=20)
date = Label(root, text = “”)
date.pack(pady = 20)

Execute Tkinter

root.mainloop()

You’ve not assigned it to anything.

Example:

# import everything from tkinter module
from tkinter import *

# create a tkinter window
root = Tk()

# Open window having dimension 100x100
root.geometry('100x100')

# Create a Button
btn = Button(root, text = 'Click me !', bd = '5', command = root.destroy)

# Set the position of button on the top of window.
btn.pack(side = 'top')

root.mainloop()

edit: I could fix your code for you, but you give it a go and post back if you hit a wall.

Note: when posting code, please use markdown formatting:

```python
#your code
```

The leading characters are known as backticks

1 Like

I will give it a try. Thank you for your quick reply and for your suggestion for posting code.
Dan

1 Like

If you are getting a syntax error, the interpreter will tell you which line has the error, and may even point a caret ^ at the place where it sees the problem.

Occasionally, the true cause of the error occurs on the previous line of code.

So if you are getting an actual SyntaxError, start by looking at the information the interpreter gives you: which line it says is at fault, the reason why (if any), and where the caret ^ points.

Nothing is obviously wrong with your code as far as I can see, but I don’t have the advantage of knowing what SyntaxError you got.

If you need help interpreting the syntax error, please copy and paste it in your reply.

Noted. Thanks

Envoyé de mon iPhone