|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这是我写的一个仿anki的程序中开始学习的模块和增加卡片模块:def begin():
root = tk.Tk()
root.title('学习')
root.geometry('600x300')
import linecache
fr = linecache.getline('./cards1.txt', 1)
ft = tkFont.Font(family='Fixdsys', size=50, weight=tkFont.BOLD)
def ans():
fk = linecache.getline('./cards2.txt', 1)
fl = linecache.getline('./cards3.txt', 1)
tk.Label(root, text=fk, font=ft).grid(column=0, row=2, padx=100, pady=10)
tk.Label(root, text=fl, font=ft).grid(column=0, row=3, padx=100, pady=10)
def de():
import fileinput
for line in fileinput.input("cards1.txt", inplace=1):
if not fileinput.isfirstline():
print(line.replace('\n', ''))
for line in fileinput.input("cards2.txt", inplace=1):
if not fileinput.isfirstline():
print(line.replace('\n', ''))
for line in fileinput.input("cards3.txt", inplace=1):
if not fileinput.isfirstline():
print(line.replace('\n', ''))
begin()
def s():
de()
def t():
for line in fileinput.input("cards1.txt", inplace=1):
if not fileinput.isfirstline():
print(line.replace('\n', ''))
for line in fileinput.input("cards2.txt", inplace=1):
if not fileinput.isfirstline():
print(line.replace('\n', ''))
for line in fileinput.input("cards3.txt", inplace=1):
if not fileinput.isfirstline():
print(line.replace('\n', ''))
with open('cards1.txt', 'a+') as f:
f.write(fr + '\n')
with open('cards2.txt', 'a+') as f:
f.write(fk + '\n')
with open('cards3.txt', 'a+') as f:
f.write(fl + '\n')
begin()
ttk.Button(root, text='熟记', command=s).grid(column=1, row=1, padx=10, pady=10)
ttk.Button(root, text='跳过', command=t).grid(column=2, row=1, padx=10, pady=10)
tk.Label(root, text=fr ,font = ft).grid(column=0, row=0, padx=100, pady=10)
ttk.Button(root, text='答案',command = ans).grid(column=0, row=1, padx=10, pady=10)
root.mainloop()
def add():
def ok():
with open('cards1.txt', 'a+') as f:
f.write(str(nameEntered.get()) + '\n')
with open('cards2.txt', 'a+') as f:
f.write(str(baEntered.get()) + '\n')
with open('cards3.txt', 'a+') as f:
f.write(str(adEntered.get()) + '\n')
answer = mBox.askyesno("通知", "已完成!是否继续增加?")
if answer == True:
add()
def sh():
mBox.showwarning('警告', '警告:内容将无法保存,您确定?')
exit(0)
monty = tk.LabelFrame(text='增加卡片')
monty.grid(column=0, row=0, padx=20, pady=20)
ttk.Label(monty, text="卡片正面:").grid(column=0, row=0, sticky='W')
name = tk.StringVar()
nameEntered = tk.Entry(monty, width=30, textvariable=name)
nameEntered.grid(column=1, row=0, sticky='W')
ttk.Label(monty, text="卡片背面:").grid(column=0, row=1, sticky='W')
ba = tk.StringVar()
baEntered = tk.Entry(monty, width=30, textvariable=ba)
baEntered.grid(column=1, row=1, sticky='W')
ttk.Label(monty, text="备注:").grid(column=0, row=2, sticky='W')
ad = tk.StringVar()
adEntered = tk.Entry(monty, width=30, textvariable=ad)
adEntered.grid(column=1, row=2, sticky='W')
action = ttk.Button(monty, text="增加", width=10, command=ok)
action.grid(column=3, row=3, rowspan=2, ipady=7)
ac = ttk.Button(monty, text="返回", width=10, command=sh)
ac.grid(column=5, row=3, rowspan=2, ipady=7)
我想要的效果:
1.当我点熟记或跳过后,自动呈现第二题
2.可以输入中文
实际:
1.我不断点他们,却还是原来的卡片和内容(明明成功删除了!)
2.输入中文就报错 |
|