This is my code:
import random
from tkinter import *
root=Tk()
a=Canvas(root, width=1000, height=1000)
a.pack()
e = Entry(root)
paralist = []
x=random.randint(1,10)
file = open("groupproject.txt")
line = file.readline()
for line in file:
paralist.append(line.replace("\n", ""));
a.create_text(500,50, text = "Typing Fun", width = 700, font = "Verdana", fill = "purple")
a.create_text(500,300, text = paralist[x], width = 700, font = "Times", fill = "purple")
#master = Tk()
#a = Entry(master)
#a.pack()
#a.focus_set()
#def callback():
# print (a.get())
root.mainloop()
The commented section is supposed to print an entry widget underneath a paragraph but instead it gives an error IndexError: list index out of range
for line a.create_text(500,300, text = paralist[x], width = 700, font = "Times", fill = "purple")
. If I use e
instead of a
it works but opens the entry widget in a separate window.
I'm trying to make the tkinter entry widget appear in the same window as the text. Can someone please tell me how to do this?