python利用mysql数据库实现一个中英文翻译程序兼单词试卷生成并改阅功能,并可以爬取有道官网进行在线翻译。

本文展示了一个使用Python结合MySQL数据库实现的中英文翻译程序,包括单词查询、录入、测试功能。此外,程序还能爬取有道官网进行在线翻译。通过截图展示了各个功能的使用情况,如单词查询、录入后的数据库状态以及单词测试的生成与改阅流程。需要注意的是,由于时间原因,文中提供的数据库可能不完整,读者需根据代码自行创建数据库。
摘要由CSDN通过智能技术生成

直接上运行截图(代码在后面)

开始界面
在这里插入图片描述

使用navicat查看mysql数据库中的数据

在这里插入图片描述

单词查询功能测试

本地翻译一个本地数据库中有的单词

在这里插入图片描述
本地翻译一个本地数据库中没有的单词
在这里插入图片描述
爬取有道官网进行在线翻译
在这里插入图片描述

单词录入功能测试

我是录入了很多单词,这里只放一张图片
在这里插入图片描述
然后查看数据库中的数据
在这里插入图片描述

单词测试功能测试

点击单词测试结果如下
在这里插入图片描述
难度选择中等后点击生成结果如下
在这里插入图片描述
在下面的输入框中输入你的答案然后点击提交,程序将会把你的试卷改出来
在这里插入图片描述

注意事项

这个程序是我好久以前用当时的电脑做的,现在电脑中本程序所需要的的数据库表并不全,大家如果需要使用的话,可以根据我的代码自己创建数据库,程序中的所有功能都是可以正常使用的。

源代码(如转发请注明出处,谢谢)

# -*- coding: utf-8 -*-
"""
Created on Tue Dec 24 13:06:14 2019

@author: 一叶落而知天下秋
"""
import random
import wx
import pymysql
from urllib import request, parse
import json
import pymysql

class priframe(wx.Frame):
    def __init__(self,sup):
        wx.Frame.__init__(self,parent=sup,title='多多瑜教育管理中心',pos=(650,300),size=(900,600))
        panel=wx.Panel(self)
        image_file = '背景2.png'
        to_bmp_image = wx.Image(image_file, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
        panel.bitmap = wx.StaticBitmap(panel,-1, to_bmp_image, (0, 0))
        #set_title = '%s %d x %d' % (image_file,200,400)
        #self.SetTitle(set_title)
        
        '''panel.Bind(wx.EVT_ERASE_BACKGROUND,self.OnEraseBack)
    def OnEraseBack(self,event):
        dc = event.GetDC()
        if not dc:
            dc = wx.ClientDC(self)
            rect = self.GetUpdateRegion().GetBox()
            dc.SetClippingRect(rect)
        dc.Clear()
        bmp = wx.Bitmap("1.jpg")
        dc.DrawBitmap(bmp, 0, 0)'''

        #wx.StaticText(parent=panel,label='欢迎来到多多瑜教育管理中心',pos=(20,20))
        bmp=wx.Image('背景21.png', wx.BITMAP_TYPE_ANY).ConvertToBitmap()
        #self.button = wx.BitmapButton(panel, -1, bmp, pos=(10, 20))
        self.buttondancichaxun=wx.Button(panel.bitmap,label='单词查询',pos=(500,250),size=(70,40))
        self.Bind(wx.EVT_BUTTON,self.onbuttondancichaxun,self.buttondancichaxun)
        self.buttondanciluru=wx.Button(parent=panel.bitmap,label='单词录入',pos=(580,250),size=(70,40))
        self.Bind(wx.EVT_BUTTON,self.onbuttondanciluru,self.buttondanciluru)
        self.buttondancixiugai=wx.Button(parent=panel.bitmap,label='单词修改',pos=(660,250),size=(70,40))
        self.Bind(wx.EVT_BUTTON,self.onbuttondancixiugai,self.buttondancixiugai)
        self.buttondancishanchu=wx.Button(parent=panel.bitmap,label='单词删除',pos=(740,250),size=(70,40))
        self.Bind(wx.EVT_BUTTON,self.onbuttondancishanchu,self.buttondancishanchu)
        self.buttonjiansuojilu=wx.Button(parent=panel.bitmap,label='检索记录',pos=(420,370),size=(70,40))
        self.Bind(wx.EVT_BUTTON,self.onbuttonjiansuojilu,self.buttonjiansuojilu)
        self.buttondanciceshi=wx.Button(parent=panel.bitmap,label='单词测试',pos=(500,370),size=(70,40))
        self.Bind(wx.EVT_BUTTON,self.onbuttondanciceshi,self.buttondanciceshi)
        self.buttonweizhijiansuo=wx.Button(parent=panel.bitmap,label='位置检索',pos=(420,310),size=(70,40))
        self.Bind(wx.EVT_BUTTON,self.onbuttonweizhijiansuo,self.buttonweizhijiansuo)
        self.buttonlijuchaxun=wx.Button(parent=panel.bitmap,label='例句查询',pos=(500,310),size=(70,40))
        self.Bind(wx.EVT_BUTTON,self.onbuttonlijuchaxun,self.buttonlijuchaxun)
        self.buttonlijuluru=wx.Button(parent=panel.bitmap,label='例句录入',pos=(580,310),size=(70,40))
        self.Bind(wx.EVT_BUTTON,self.onbuttonlijuluru,self.buttonlijuluru)
        self.buttonlijuxiugai=wx.Button(parent=panel.bitmap,label='例句修改',pos=(660,310),size=(70,40))
        self.Bind(wx.EVT_BUTTON,self.onbuttonlijuxiugai,self.buttonlijuxiugai)
        self.buttonlijushanchu=wx.Button(parent=panel.bitmap,label='例句删除',pos=(740,310),size=(70,40))
        self.Bind(wx.EVT_BUTTON,self.onbuttonlijushanchu,self.buttonlijushanchu)
        self.buttonduanyuchaxun=wx.Button(parent=panel.bitmap,label='短语查询',pos=(580,370),size=(70,40))
        self.Bind(wx.EVT_BUTTON,self.onbuttonduanyuchaxun,self.buttonduanyuchaxun)
        self.buttonbeifen=wx.Button(parent=panel.bitmap,label='数据备份',pos=(660,370),size=(70,40))
        self.Bind(wx.EVT_BUTTON,self.onbuttonbeifen,self.buttonbeifen)
        self.buttonhuifu=wx.Button(parent=panel.bitmap,label='数据恢复',pos=(740,370),size=(70,40))
        self.Bind(wx.EVT_BUTTON,self.onbuttonhuifu,self.buttonhuifu)
        self.buttonwenjianchuangjian=wx.Button(panel.bitmap,label='创建文件',pos=(420,250),size=(70,40))
        self.Bind(wx.EVT_BUTTON,self.onbuttonwenjianchuangjian,self.buttonwenjianchuangjian)
    def onbuttonbeifen(self,event):
        conn=pymysql.connect(host='localhost',user='root',passwd='123456',db='sys')
        conn2=pymysql.connect(host='localhost',user='root',passwd='123456',db='sys')
        cur=conn.cursor()
        cur2=conn2.cursor()
       
        cur2.execute('delete from Wordbeifen')
        print('123')
        #row=cur.fetchone()
        #shuliang=row[0]
        cur.execute('select * from Word')
        row22=cur.fetchone()
        print(row22)
        while row22:
            cur2.execute('insert into Wordbeifen(danci,fanyi,difficulty) values(%s,%s,%d)',(row22[0],row22[1],row22[2]))
            row22=cur.fetchone()
            print(row22)
        conn.commit()
        conn2.commit()
        cur.close()
        cur2.close()
        conn.close()
        conn2.close()
        beifenframe(None).Show()
    def onbuttonhuifu(self,event):
        conn=pymysql.connect(host='localhost',user='root',passwd='123456',db='sys')
        conn2=pymysql.connect(host='localhost',user='root',passwd='123456',db='sys')
        cur=conn.cursor()
        cur2=conn2.cursor()
       
        cur2.execute('delete from Word')
        print('123')
        #row=cur.fetchone()
        #shuliang=row[0]
        cur.execute('select * from Wordbeifen')
        row22=cur.fetchone()
        print(row22)
        while row22:
            cur2.execute('insert into Word(danci,fanyi,difficulty) values(%s,%s,%d)',(row22[0],row22[1],row22[2]))
            row22=cur.fetchone()
            print(row22)
        conn.commit()
        conn2.commit()
        cur.close()
        cur2.close()
        conn.close()
        conn2.close()
        huifuframe(None).Show()
    def onbuttondancichaxun(self,event):
        dancichaxunframe(None).Show()
    def onbuttondanciluru(self,event):
        danciluruframe(None).Show()
    def onbuttondancixiugai(self,event):
        dancixiugaiframe(None).Show()
    def onbuttondancishanchu(self,event):
        dancishanchuframe(None).Show() 
    def onbuttondanciceshi(self,event):
        danciceshiframe(None).Show() 
    def onbuttonlijuchaxun(self,event):
        lijuchaxunframe(None).Show()
    def onbuttonlijuluru(self,event):
        lijuluruframe(None).Show()
    def onbuttonlijuxiugai(self,event):
        lijuxiugaiframe(None).Show()
    def onbuttonlijushanchu(self,event):
        lijushanchuframe(None).Show()
    def onbuttonduanyuchaxun(self,event):
        duanyuchaxunframe(None).Show()
    def onbuttonwenjianchuangjian(self,event):
        wenjianchuangjianframe(None).Show()
    def onbuttonweizhijiansuo(self,event):
        weizhijiansuoframe(None).Show()
    def onbuttonjiansuojilu(self,event):
        jiansuojiluframe(None).Show()
class beifenframe(wx.Frame):
    def __init__(self,sup):
        wx.Frame.__init__(self,parent=sup,title
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值