这是我的代码:
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()
被注释的部分应该在段落下面打印一个条目小部件,但它会给IndexError: list index out of rangeline错误a.create_text(500,300, text = paralist[x], width = 700, font = "Times", fill = "purple")。如果我使用e而不是a它可以工作,但是会在一个单独的窗口中打开条目小部件。
我试图使tkinter条目窗口小部件与文本显示在同一窗口中。有人可以告诉我该怎么做吗?
慕娘9325324
白衣染霜花
相关分类