用Python的内置包Tkinter写一个练习系统6.0

登录系统

生日系统

抽奖系统

抽奖系统1.0

抽奖系统2.0

抽奖系统3.0

练习系统

练习系统1.0

练习系统2.0

练习系统3.0

练习系统4.0

练习系统5.0

练习系统6.0

练习系统6.0 

录入选择题 

        def insert():
            num=var1.get()
            question=var2.get()
            choice=var3.get()
            answer=var4.get()
            with open('d:\\登录系统\\%s\\练习三3.1.pickle'%(user_name),'rb') as file:
                lst1=pickle.load(file)
            with open('d:\\登录系统\\%s\\练习三3.2.pickle'%(user_name),'rb') as file:
                lst2=pickle.load(file)
            with open('d:\\登录系统\\%s\\练习三3.3.pickle'%(user_name),'rb') as file:
                lst3=pickle.load(file)
            with open('d:\\登录系统\\%s\\练习三3.4.pickle'%(user_name),'rb') as file:
                lst4=pickle.load(file)
            if num not in lst1:
                lst1.append(num)
                lst2.append(question)
                lst3.append(choice)
                lst4.append(answer)
                var5.set('录入成功')
            else:
                var5.set('录入失败')
            with open('d:\\登录系统\\%s\\练习三3.1.pickle'%(user_name),'wb') as file:
                pickle.dump(lst1,file)
                file.close()
            with open('d:\\登录系统\\%s\\练习三3.2.pickle'%(user_name),'wb') as file:
                pickle.dump(lst2,file)
                file.close()
            with open('d:\\登录系统\\%s\\练习三3.3.pickle'%(user_name),'wb') as file:
                pickle.dump(lst3,file)
                file.close() 
            with open('d:\\登录系统\\%s\\练习三3.4.pickle'%(user_name),'wb') as file:
                pickle.dump(lst4,file)
                file.close()  

删除选择题 

        def delete():
            num=var1.get()
            question=var2.get()
            choice=var3.get()
            answer=var4.get()
            with open('d:\\登录系统\\%s\\练习三3.1.pickle'%(user_name),'rb') as file:
                lst1=pickle.load(file)
            with open('d:\\登录系统\\%s\\练习三3.2.pickle'%(user_name),'rb') as file:
                lst2=pickle.load(file)
            with open('d:\\登录系统\\%s\\练习三3.3.pickle'%(user_name),'rb') as file:
                lst3=pickle.load(file)
            with open('d:\\登录系统\\%s\\练习三3.4.pickle'%(user_name),'rb') as file:
                lst4=pickle.load(file)
            if num in lst1:
                t=lst1.index(num)
                lst1.pop(t)
                lst2.pop(t)
                lst3.pop(t)
                lst4.pop(t)
                var5.set('删除成功')
            else:
                var5.set('删除失败')
            with open('d:\\登录系统\\%s\\练习三3.1.pickle'%(user_name),'wb') as file:
                pickle.dump(lst1,file)
                file.close()
            with open('d:\\登录系统\\%s\\练习三3.2.pickle'%(user_name),'wb') as file:
                pickle.dump(lst2,file)
                file.close()
            with open('d:\\登录系统\\%s\\练习三3.3.pickle'%(user_name),'wb') as file:
                pickle.dump(lst3,file)
                file.close() 
            with open('d:\\登录系统\\%s\\练习三3.4.pickle'%(user_name),'wb') as file:
                pickle.dump(lst4,file)
                file.close()  

练习系统6.0 

flag2=1
user_name='wjw'
def xuanze():
    global flag2
    if flag2==1:
        root_tiankong=tk.Tk()
        root_tiankong.title('选择题')
        screenheight=root_tiankong.winfo_screenheight()
        screenwidth=root_tiankong.winfo_screenwidth()
        height=300
        width=500
        x=(screenwidth-width)//2
        y=(screenheight-height)//2
        root_tiankong.geometry('%dx%d+%d+%d'%(width,height,x,y))
        tk.Label(root_tiankong,text='选择题',font=('宋体',20),fg='red',width=10,height=2).place(x=180,y=0)
        tk.Label(root_tiankong,text='题号:',font=('宋体',12),fg='black',width=5).place(x=100,y=60)
        tk.Label(root_tiankong,text='题目:',font=('宋体',12),fg='black',width=5).place(x=100,y=100)
        tk.Label(root_tiankong,text='选项:',font=('宋体',12),fg='black',width=5).place(x=100,y=140)        
        tk.Label(root_tiankong,text='答案:',font=('宋体',12),fg='black',width=5).place(x=100,y=180)
        var1=tk.StringVar()
        var2=tk.StringVar()
        var3=tk.StringVar()
        var4=tk.StringVar()
        var5=tk.StringVar()
        def insert():
            num=var1.get()
            question=var2.get()
            choice=var3.get()
            answer=var4.get()
            with open('d:\\登录系统\\%s\\练习三3.1.pickle'%(user_name),'rb') as file:
                lst1=pickle.load(file)
            with open('d:\\登录系统\\%s\\练习三3.2.pickle'%(user_name),'rb') as file:
                lst2=pickle.load(file)
            with open('d:\\登录系统\\%s\\练习三3.3.pickle'%(user_name),'rb') as file:
                lst3=pickle.load(file)
            with open('d:\\登录系统\\%s\\练习三3.4.pickle'%(user_name),'rb') as file:
                lst4=pickle.load(file)
            if num not in lst1:
                lst1.append(num)
                lst2.append(question)
                lst3.append(choice)
                lst4.append(answer)
                var5.set('录入成功')
            else:
                var5.set('录入失败')
            with open('d:\\登录系统\\%s\\练习三3.1.pickle'%(user_name),'wb') as file:
                pickle.dump(lst1,file)
                file.close()
            with open('d:\\登录系统\\%s\\练习三3.2.pickle'%(user_name),'wb') as file:
                pickle.dump(lst2,file)
                file.close()
            with open('d:\\登录系统\\%s\\练习三3.3.pickle'%(user_name),'wb') as file:
                pickle.dump(lst3,file)
                file.close() 
            with open('d:\\登录系统\\%s\\练习三3.4.pickle'%(user_name),'wb') as file:
                pickle.dump(lst4,file)
                file.close() 
        def delete():
            num=var1.get()
            question=var2.get()
            choice=var3.get()
            answer=var4.get()
            with open('d:\\登录系统\\%s\\练习三3.1.pickle'%(user_name),'rb') as file:
                lst1=pickle.load(file)
            with open('d:\\登录系统\\%s\\练习三3.2.pickle'%(user_name),'rb') as file:
                lst2=pickle.load(file)
            with open('d:\\登录系统\\%s\\练习三3.3.pickle'%(user_name),'rb') as file:
                lst3=pickle.load(file)
            with open('d:\\登录系统\\%s\\练习三3.4.pickle'%(user_name),'rb') as file:
                lst4=pickle.load(file)
            if num in lst1:
                t=lst1.index(num)
                lst1.pop(t)
                lst2.pop(t)
                lst3.pop(t)
                lst4.pop(t)
                var5.set('删除成功')
            else:
                var5.set('删除失败')
            with open('d:\\登录系统\\%s\\练习三3.1.pickle'%(user_name),'wb') as file:
                pickle.dump(lst1,file)
                file.close()
            with open('d:\\登录系统\\%s\\练习三3.2.pickle'%(user_name),'wb') as file:
                pickle.dump(lst2,file)
                file.close()
            with open('d:\\登录系统\\%s\\练习三3.3.pickle'%(user_name),'wb') as file:
                pickle.dump(lst3,file)
                file.close() 
            with open('d:\\登录系统\\%s\\练习三3.4.pickle'%(user_name),'wb') as file:
                pickle.dump(lst4,file)
                file.close() 
        tk.Entry(root_tiankong,textvariable=var1,width=30).place(x=150,y=60)
        tk.Entry(root_tiankong,textvariable=var2,width=30).place(x=150,y=100)
        tk.Entry(root_tiankong,textvariable=var3,width=30).place(x=150,y=140)
        tk.Entry(root_tiankong,textvariable=var4,width=30).place(x=150,y=180)
        tk.Button(root_tiankong,text='录入',font=('宋体',12),width=5,bg='red',fg='white',command=insert).place(x=200,y=210)
        tk.Button(root_tiankong,text='删除',font=('宋体',12),width=5,bg='black',fg='white',command=delete).place(x=260,y=210) 
        tk.Label(root_tiankong,textvariable=var5,font=('宋体',12),bg='white',fg='red',width=10).place(x=210,y=250)
        root_tiankong.mainloop()
    else:
        pass
xuanze() 

猜你喜欢

转载自blog.csdn.net/m0_68111267/article/details/128686842