Where is the syntax error in my Python Script?
Looks like your problem is that you are trying to run python main.py from within the Python interpreter, which is why you're seeing that traceback.
Make sure you're out of the interpreter:
exit()
Then run the python main.py command from bash or command prompt or whatever.
Invoke python scripts like this:
PS C:\Users\sween\Desktop> python ./a.py
Not like this:
PS C:\Users\sween\Desktop> python
Python 3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> ./a.py
File "<stdin>", line 1
./a.py
^
SyntaxError: invalid syntax
The three arrows >>>
indicate a place to write Python code, not filenames or paths.
First thing I noticed was you need to switch out root.Canvas
with tk.Canvas
.
import tkinter as tk
from tkinter import filedialog, Text
import os
root = tk.Tk()
canvas = tk.Canvas(root, height=700, width=700, bg="#263d42")
canvas.pack()
root.mainloop()
Although even using your original unedited script, it didn't result in a SyntaxError, but an AttributeError for the canvas. I'm working from Pycharm, my assumption is you're working from command line? It looks like you're running main.py from within the interpreter, which you should be able to use exit()
to resolve. The post linked here goes into more detail on that.