我正在用 Python 3 编写一个打字练习游戏,它利用了 tkinter。到目前为止,我的代码能够让用户输入内容并使用按钮打印他们输入的内容:
import random
from tkinter import *
root=Tk()
a=Canvas(root, width=500, height=500)
a.pack()
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(250,50, text = "Typing Fun", width = 500, font = "Verdana", fill = "purple")
a.create_text(250,300, text = paralist[x], width = 500, font = "Times", fill = "purple")
a = Entry(root, width = 100)
a.pack()
a.focus_set()
def callback():
s = a.get()
print (s)
b = Button(root, text="Enter", command=callback)
b.pack()
root.mainloop()
我的文本文件基本上是 10 个单行句子。
我想在输入时将用户在条目小部件中输入的每个字符存储在变量(或列表或数组)中(不按回车键。)
非常感谢您提前提供的帮助!!:D