I need to write a few lines from a file to the canvas. the error is bad screen distance. Can someone please help me?
f = open(“mytus_fakt.txt”, “r”, encoding = “utf-8”)
for i,row in enumerate(f):
x = row.split(“\t”)
canvas.create_text(x,y-750, text = x[0])
The way in which you’ve coded canvas.create_text()
looks a little off to me.
Have a look at this:
It’s a very good guide; not just for ‘beginners’, as the title would suggest, but a good reference site for any Tkinter coder.
x
, the horizontal screen distance from left edge of canvas, must be an int (non-zero I believe), but it is a list in your program. Hence ‘bad screen distance’. I believe of y
, which is not defined.
Your example is missing indents under for
. Put code between triple backtick lines.
```
f = ....
...
```
For question examples, one should usually post a short list of strings representing file lines, instead of a reference to a private file.