100以内四则运算练习(千纬数学)再次更新,选取难题

   100以内四则运算练习(千纬数学app)正式版及其源码-CSDN博客

有一段时间,小孩子没有用,我也没有去留意,最近拿出来给小孩子用,发现存在一个问题,就是出题是随机的,这样实际效率不高,比如出一些如1+2=3,51+5=56之类的题,这些题做久了,对运算的提升是否有作用,题库是10000多条,这些简单的题应该占比不少,也会浪费一定时间。

    为此,我修改了代码,在原ys表中的cuo列,修改其用途,用于记录每答一题的时间,这个时间数据是用20秒去减去答题的秒数记录的,比如做题速度为3秒,那个这个数值就是17,也就是说数值越大说明该题的做题速度越快,这样做的目的是为了排序,按正序去排列要提取的题目,数值大即做题速度越快的题目就会沉淀在后面不会被提取出来,提取出来的是一些答题速度慢的题目。当然也要有一定的随机性,我假设全部题目都有答,那么就在答题速度慢的50道题中抽题。当然一开始的cuo的数据都是0,那么就在cuo数值较小的范围内选题,这样一圈,全部的题目都答完了,在从答题速度慢的题目选题答。我还设定当一道题答错,那么cuo会变为0,cuo也会记录答题速度最快的数据。通过这个提高孩子的运算能力。

源码如下:

from functools import partial
import toga
from toga.style.pack import COLUMN, LEFT, RIGHT, ROW, Pack
import sqlite3
import random
from time import time,sleep
from pathlib import Path
import datetime
import shutil
import miniaudio
import threading
#导入必要的库

resources_folder = Path(__file__).joinpath("../resources/").resolve()
db_filepath = resources_folder.joinpath("qwsx.db")
#测试参数1为手机,0为电脑,2为boox平板
sjcs = 1
if sjcs == 1:
    sj_file = '/data/data/com.qwsx.qwsx/qwsx.db'
    if Path(sj_file).exists():
        db_filepath = sj_file
    else:
        shutil.copy(db_filepath, sj_file)
        db_filepath = sj_file
elif sjcs == 2:
    db_filepath = '/storage/emulated/0/Pictures/qwsx.db'
conn = sqlite3.connect(db_filepath, timeout=10, check_same_thread=False)
c = conn.cursor()
current_date = datetime.datetime.now()
formatted_date = current_date.strftime("%Y-%m-%d")
cursor = c.execute("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='jfen'")
row = cursor.fetchone()
have_jfena = row[0]
if have_jfena == 0:
    c.execute('''CREATE TABLE jfen (
    jid INTEGER PRIMARY KEY AUTOINCREMENT,
    rq  TEXT,
    jf  INTEGER);
    ''')
    conn.commit()
cursor = c.execute("SELECT count(*) FROM jfen WHERE rq='"+ formatted_date +"'")
row = cursor.fetchone()
if row[0] == 0:
    query_sql = "INSERT INTO jfen (rq,jf) VALUES (?,?);"
    c.execute(query_sql, (formatted_date,0,))
    conn.commit()
c.close()
conn.close()
#建积分表,并插入一行今日积分
names = globals()
nd = 0
hd = 0 #回答为0为出题,回答为1为1位数答题,2为2位数答题,3为3位数答题,4为符号答题
dan = 101 #初始答案
dan1 = 0
dan2 = 0
dan3 = 0
tjcs = ''

def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        pass
    try:
        import unicodedata
        unicodedata.numeric(s)
        return True
    except (TypeError, ValueError):
        pass
    return False
#判断是不是数字
def u_jfen(jf):
    if jf > 0 or (jf < 0 and globals()['cuo'] <= 1):
        conn = sqlite3.connect(db_filepath, timeout=10, check_same_thread=False)
        c = conn.cursor()
        current_date = datetime.datetime.now()
        formatted_date = current_date.strftime("%Y-%m-%d")
        cursor = c.execute("SELECT count(*) FROM jfen WHERE rq='"+ formatted_date +"'")
        row = cursor.fetchone()
        if row[0] ==0:
            query_sql = "INSERT INTO jfen (rq,jf) VALUES (?,?);"
            c.execute(query_sql, (formatted_date,0,))
            conn.commit()
            query_sql = "update jfen set jf = jf + ? where rq= ?"
            c.execute(query_sql, (jf,formatted_date,))
            conn.commit()
        else:
            query_sql = "update jfen set jf = jf + ? where rq= ?"
            c.execute(query_sql, (jf,formatted_date,))
            conn.commit()
        c.close()
        conn.close()
#更新积分,增加积分,中间再次判断今日的数据行是否存在是为了跨日做题不出错
def bfnum(number):
    conn = sqlite3.connect(db_filepath, timeout=10, check_same_thread=False)
    c = conn.cursor()
    cursor = c.execute("SELECT sc from voice where number = ?;",(number,))
    row = cursor.fetchone()
    sc = row[0]
    c.close()
    conn.close()
    stream = miniaudio.stream_file(str(resources_folder.joinpath(str(number) + '.wav')))
    with miniaudio.PlaybackDevice() as device:
        device.start(stream)
        sleep(sc)
def bffh(fh):
    if fh == '+':
        stream = miniaudio.stream_file(str(resources_folder.joinpath('jia.wav')))
        with miniaudio.PlaybackDevice() as device:
            device.start(stream)
            sleep(0.92)
    if fh == '-':
        stream = miniaudio.stream_file(str(resources_folder.joinpath('jian.wav')))
        with miniaudio.PlaybackDevice() as device:
            device.start(stream)
            sleep(0.948)
    if fh == '*':
        stream = miniaudio.stream_file(str(resources_folder.joinpath('sheng.wav')))
        with miniaudio.PlaybackDevice() as device:
            device.start(stream)
            sleep(0.975)
    if fh == '/':
        stream = miniaudio.stream_file(str(resources_folder.joinpath('chu.wav')))
        with miniaudio.PlaybackDevice() as device:
            device.start(stream)
            sleep(0.975)
    if fh == '□':
        stream = miniaudio.stream_file(str(resources_folder.joinpath('duo.wav')))
        with miniaudio.PlaybackDevice() as device:
            device.start(stream)
            sleep(1.066)
    if fh == '=':
        stream = miniaudio.stream_file(str(resources_folder.joinpath('deng.wav')))
        with miniaudio.PlaybackDevice() as device:
            device.start(stream)
            sleep(0.975)
    if fh == 'fh':
        stream = miniaudio.stream_file(str(resources_folder.joinpath('tian.wav')))
        with miniaudio.PlaybackDevice() as device:
            device.start(stream)
            sleep(0.975)
def bfsz(t1,tfh1,t2,tfh2,tdan):
    if is_number(t1):
        pnum(t1)
        sleep(0.65)
    elif t1 == '□':
        pfh('□')
        sleep(0.6)
    pfh(tfh1)
    sleep(0.6)
    if is_number(t2):
        pnum(t2)
        sleep(0.65)
    elif t2 == '□':
        pfh('□')
        sleep(0.6)
    pfh(tfh2)
    sleep(0.5)
    if is_number(tdan):
        pnum(tdan)
        sleep(0.5)
    elif tdan == '□':
        pfh('□')
        sleep(0.5)
#上面用sleep调节播放数字和运算符号的速度,可以再修改
def settm(nd):
    conn = sqlite3.connect(db_filepath, timeout=10, check_same_thread=False)
    c = conn.cursor()
    
    if nd == 1:
        cursor = c.execute("SELECT count(tid) from ys where (fh = 0 or fh = 1) and cuo < 50;")
        row = cursor.fetchone()
        if row[0] > 50:
            maxid = row[0]
        else:
            maxid = 50
        rant = random.randint(0, maxid)
        cursor = c.execute(f"SELECT * from ys where fh = 0 or fh = 1 ORDER BY cuo ASC LIMIT {rant},1;")
        row = cursor.fetchone()
        tid = row[0]
        s1 = row[1]
        jj = row[2]
        s2 = row[3]
        dan = row[4]
    else:
        #按数据库乘法除法只有600题,加减法各5151题,如果随机经常是加减法,按25%概率强制出现乘法除法题        
        if random.randint(0,3) == 3:
            cursor = c.execute("SELECT count(tid) from ys where (fh = 2 or fh = 3) and cuo < 50;")
            row = cursor.fetchone()
            if row[0] > 50:
                maxid = row[0]
            else:
                maxid = 50
            rant = random.randint(0, maxid)
            cursor = c.execute(f"SELECT * from ys where fh = 2 or fh = 3 ORDER BY cuo ASC LIMIT {rant},1;")
        else:
            cursor = c.execute("SELECT count(tid) from ys where cuo < 50;")
            row = cursor.fetchone()
            if row[0] > 50:
                maxid = row[0]
            else:
                maxid = 50
            rant = random.randint(0, maxid)
            cursor = c.execute(f"SELECT * from ys ORDER BY cuo ASC LIMIT {rant},1;")
        row = cursor.fetchone()
        tid = row[0]
        s1 = row[1]
        jj = row[2]
        s2 = row[3]
        dan = row[4]
    c.close()
    conn.close()
    # print(maxid)
    if jj == 0:
        #为加法 
        cvalue = str(s1) + "+" + str(s2) + "=" 
        hd = 1
        ii = random.randint(0,4) #0为提交答案
        if ii == 2:
            cvalue = "□+" + str(s2) + "=" + str(dan) + ",□为"
            plays('□','+',s2,'=',dan)
            dan = s1
        elif ii == 3:
            cvalue = str(s1) + "+□=" + str(dan) + ",□为"
            plays(s1,'+','□','=',dan)
            dan = s2
        elif ii ==4 and s2 > 0:#a+0=a,a-0=a,可以是+-
            cvalue = str(s1) + "□" + str(s2) + "=" + str(dan) + ",□为"
            bffh('fh')
            dan = jj
            hd = 4 #hd4为符号
        else:
            plays(s1,'+',s2,'=','□')
    elif jj ==1:
        cvalue = str(s1) + "-" + str(s2) + "=" 
        hd = 1
        ii = random.randint(0,4) #0为提交答案
        if ii == 2:
            cvalue = "□-" + str(s2) + "=" + str(dan) + ",□为"
            plays('□','-',s2,'=',dan)
            dan = s1
        elif ii == 3:
            cvalue = str(s1) + "-□=" + str(dan) + ",□为"
            plays(s1,'-','□','=',dan)
            dan = s2
        elif ii ==4 and s2 > 0:#a+0=a,a-0=a,可以是+-
            cvalue = str(s1) + "□" + str(s2) + "=" + str(dan) + ",□为"
            bffh('fh')
            dan = jj
            hd = 4 #hd4为符号
        else:
            plays(s1,'-',s2,'=','□')
    elif jj ==2:
        #乘法
        cvalue = str(s1) + "×" + str(s2) + "="
        hd = 1
        ii = random.randint(0,4) #0为提交答案
        if ii == 2 and s2 !=0:#a*0=0 上次程序这个没有限制s2不等于0,bug!
            cvalue = "□×" + str(s2) + "=" + str(dan) + ",□为"
            plays('□','*',s2,'=',dan)
            dan = s1
        elif ii == 3 and s1 != 0:#a*0=0,b*0=0
            cvalue = str(s1) + "×□=" + str(dan) + ",□为"
            plays(s1,'*','□','=',dan)
            dan = s2
        elif ii ==4 and s2 !=1 and s1 != 0:#a*1=a,a/1=a;0*a=0,0/a=0
            cvalue = str(s1) + "□" + str(s2) + "=" + str(dan) + ",□为"
            bffh('fh')
            dan = jj
            hd = 4 #hd4为符号
        else:
            plays(s1,'*',s2,'=','□')
    elif jj ==3:
        cvalue = str(s1) + "÷" + str(s2) + "=" 
        hd = 1
        ii = random.randint(0,4) #0为提交答案
        if ii == 2:
            cvalue = "□÷" + str(s2) + "=" + str(dan) + ",□为"
            plays('□','/',s2,'=',dan)
            dan = s1
        elif ii == 3 and s1 > 0:#0/a=0
            cvalue = str(s1) + "÷□=" + str(dan) + ",□为"
            plays(s1,'/','□','=',dan)
            dan = s2
        elif ii ==4 and s2 !=1 and s1 !=0:#a*1=a,a/1=a;0*a=0,0/a=0
            cvalue = str(s1) + "□" + str(s2) + "=" + str(dan) + ",□为"
            bffh('fh')
            dan = jj
            hd = 4 #hd4为符号
        else:
            plays(s1,'/',s2,'=','□')
    current_date = datetime.datetime.now()
    formatted_date = current_date.strftime("%Y-%m-%d")
    formatted_time = current_date.strftime("%H:%M:%S")
    conn = sqlite3.connect(db_filepath, timeout=10, check_same_thread=False)
    c = conn.cursor()
    c.execute("INSERT INTO record (rq,sj,tid,cuo,yt) VALUES (?,?,?,?,?);", (formatted_date,formatted_time,0,0,0))
    conn.commit()
    cursor = c.execute("SELECT cid from record order by cid desc")
    row = cursor.fetchone()
    cid = row[0] 
    c.close()
    conn.close()
    return(jj,dan,hd,cid,tid,cvalue)
#设置题目,并生成记录,用于记录错误,答题用时
def u_record(yt,cid,tid):    
    if yt > 0 and cid > 0 and tid >0:
        cuoyt = 20000 - yt #20秒减去做题时间,如果做题时间大于20秒,即为负,负数变为0
        if cuoyt < 0:
            cuoyt = 0
        conn = sqlite3.connect(db_filepath, timeout=10, check_same_thread=False)
        c = conn.cursor()      
        cursor = c.execute("SELECT cuo from ys WHERE tid = ?;", (tid,))
        row = cursor.fetchone()
        cuo0 = row[0] #获取原做题速度,如做题5秒,那么原错为15秒,按最快做题速度更新
        if cuo0 >= cuoyt:
            pass
        else:
            c.execute("UPDATE ys SET cuo = ? WHERE tid = ?;", (cuoyt,tid,))
            conn.commit()
        c.execute("UPDATE record SET tid = ?, yt = ? WHERE cid = ?;", (tid,yt,cid))
        conn.commit()
        c.execute("UPDATE ys SET cs = cs + 1 WHERE tid = ?;", (tid,))
        conn.commit()
        c.close()
        conn.close()
#记录答题用时,题目答对次数
def jf_ytime(ytime):
    if ytime < 1000:
        jfen = 10
    elif ytime >=1000 and ytime <2000:
        jfen = 9
    elif ytime >=2000 and ytime <3000:
        jfen = 8
    elif ytime >=3000 and ytime <4000:
        jfen = 7
    elif ytime >=4000 and ytime <5000:
        jfen = 6
    elif ytime >=5000 and ytime <6000:
        jfen = 4
    elif ytime >=6000 and ytime <7000:
        jfen = 3
    elif ytime >=7000 and ytime <8000:
        jfen = 2
    elif ytime >=8000 and ytime <20000:
        jfen = 1
    else:
        jfen = 0
    return(jfen)
#用时转化为积分的表,大于20秒不给积分,反应越快积分越高
def u_cuo(cid,tid):
    if cid > 0 and tid > 0 and globals()['cuo'] <= 1:
        conn = sqlite3.connect(db_filepath, timeout=10, check_same_thread=False)
        c = conn.cursor()                
        c.execute("UPDATE record SET cuo = cuo + 1 WHERE cid = ?;", (cid,))
        conn.commit()
        # c.execute("UPDATE ys SET cuo = cuo + 1 WHERE tid = ?;", (tid,))
        # conn.commit()  
        # ys表的cuo用于记录用时,在这里不再更新
        c.execute("UPDATE ys SET cuo = 0 WHERE tid = ?;", (tid,))
        conn.commit()  
        # ys表的cuo用于记录用时,出现错误,就把用时清理为0
        c.close()
        conn.close()
#记录错误记录
def tj_cs():
    if globals()['hd'] == 4 or globals()['tjcs'] =='':
        conn = sqlite3.connect(db_filepath, timeout=10, check_same_thread=False)
        c = conn.cursor()
        cursor = c.execute("SELECT sum(jf) from jfen")
        row = cursor.fetchone()
        zjf = row[0]
        current_date = datetime.datetime.now()
        formatted_date = current_date.strftime("%Y-%m-%d")
        cursor = c.execute("SELECT jf from jfen where rq = '" + formatted_date + "' limit 0,1")
        row = cursor.fetchone()
        jtjf = row[0]
        stext3 = "总积分:%d,今日积分:%d \n" % (zjf,jtjf)
        query_str = 'select rq,count(cid),sum(cuo),round(avg(yt),0),sum(yt) from record where yt > 0 and yt < 240000 group by rq order by rq desc limit 0,3;'
        cursor = c.execute(query_str)
        rows = cursor.fetchall()
        for row in rows:
            stext3 += "%s:做%d题,错%d次,平均用%d毫秒,学习%d分钟\n" % (row[0],row[1],row[2],row[3],int(row[4]/60000))
        c.close()
        conn.close()
        globals()['tjcs'] = stext3
        stext4 = stext3 + "(已更新)"
    else:
        stext3 = globals()['tjcs']
        stext4 = stext3 + "(待更新)"
    return(stext4)
#显示做题记录
def build(app):
    # 定义组件
    c_box = toga.Box()
    b1_box = toga.Box()
    b2_box = toga.Box()
    b3_box = toga.Box()
    b4_box = toga.Box()
    box = toga.Box()
    c_input = toga.TextInput(readonly=True,style=Pack(font_size=22))
    c_label = toga.Label("请选择难、易开始学习...", style=Pack(text_align=LEFT))
    c_label1 = toga.Label("", style=Pack(text_align=LEFT, font_size=12))
    c_label2 = toga.Label("", style=Pack(text_align=LEFT))
    c_label3 = toga.Label("", style=Pack(text_align=LEFT))
    #界面设置
    def bt1(bb, widget):
        #选择难易,然后出题,答题,再出题
        c_label3.text = tj_cs()
        if bb == '难':
            globals()['nd'] = 2
            c_label.text = '100以内加减乘除。'
        elif bb == '易':
            globals()['nd'] = 1
            c_label.text = '100以内加减。'
        if nd >= 1 and hd == 0:
            globals()['jj'],globals()['dan'],globals()['hd'],globals()['cid'],globals()['tid'],cvalue=settm(nd)
            c_input.value = cvalue
            globals()['cuo'] = 0
            globals()['begintime'] = time()
        if bb in '+-×÷' and hd == 4:
            ytime = int((time() - begintime) * 1000)
            if bb == '+' and jj == 0:
                jf = jf_ytime(ytime)
                c_label1.text = '你答对了' + ',本题取得' + str(jf) + '积分'                
                u_record(ytime,cid,tid)
                u_jfen(jf)
                c_input.value = c_input.value + bb
                c_label2.text = '复习:' + c_input.value
                globals()['jj'],globals()['dan'],globals()['hd'],globals()['cid'],globals()['tid'],cvalue=settm(nd)
                bb = ''
                globals()['cuo'] = 0
                c_input.value = cvalue
                globals()['begintime'] = time()
            elif bb == '-' and jj == 1:
                jf = jf_ytime(ytime)
                c_label1.text = '你答对了' + ',本题取得' + str(jf) + '积分'                
                u_record(ytime,cid,tid)
                u_jfen(jf)
                c_input.value = c_input.value + bb
                c_label2.text = '复习:' + c_input.value
                globals()['jj'],globals()['dan'],globals()['hd'],globals()['cid'],globals()['tid'],cvalue=settm(nd)
                bb = ''
                globals()['cuo'] = 0
                c_input.value = cvalue
                globals()['begintime'] = time()
            elif bb == '×' and jj == 2:
                jf = jf_ytime(ytime)
                c_label1.text = '你答对了' + ',本题取得' + str(jf) + '积分'                
                u_record(ytime,cid,tid)
                u_jfen(jf)
                c_input.value = c_input.value + bb
                c_label2.text = '复习:' + c_input.value
                globals()['jj'],globals()['dan'],globals()['hd'],globals()['cid'],globals()['tid'],cvalue=settm(nd)
                bb = ''
                globals()['cuo'] = 0
                c_input.value = cvalue
                globals()['begintime'] = time()
            elif bb == '÷' and jj == 3:
                jf = jf_ytime(ytime)
                c_label1.text = '你答对了' + ',本题取得' + str(jf) + '积分'                
                u_record(ytime,cid,tid)
                u_jfen(jf)
                c_input.value = c_input.value + bb
                c_label2.text = '复习:' + c_input.value
                globals()['jj'],globals()['dan'],globals()['hd'],globals()['cid'],globals()['tid'],cvalue=settm(nd)
                bb = ''
                globals()['cuo'] = 0
                c_input.value = cvalue
                globals()['begintime'] = time()
            else:
                c_label1.text = '答错了,重新回答,本次扣2分'
                globals()['cuo'] += 1
                u_cuo(cid,tid)
                jf = -2
                u_jfen(jf)
                globals()['hd'] = 4
        if is_number(bb) and hd == 3:
            ytime = int((time() - begintime) * 1000)
            dan3 = 0
            if str(dan3) == bb:
                jf = jf_ytime(ytime)
                c_label1.text = '你答对了' + ',本题取得' + str(jf) + '积分'                
                u_record(ytime,cid,tid)
                u_jfen(jf)
                c_input.value = c_input.value + bb
                c_label2.text = '复习:' + c_input.value
                globals()['jj'],globals()['dan'],globals()['hd'],globals()['cid'],globals()['tid'],cvalue=settm(nd)
                bb = ''
                globals()['cuo'] = 0
                c_input.value = cvalue
                globals()['begintime'] = time()
            else:
                c_label1.text = '答错了,本次扣2分,答对了2个数字,请输入下一个'
                globals()['cuo'] += 1
                u_cuo(cid,tid)
                jf = -2
                u_jfen(jf)
                globals()['hd'] = 3

        if is_number(bb) and hd == 2:
            ytime = int((time() - begintime) * 1000)
            if dan >= 10 and dan < 100:
                dan2 = int(str(dan)[-1:])
                if dan2 == int(bb):
                    jf = jf_ytime(ytime)
                    c_label1.text = '你答对了' + ',本题取得' + str(jf) + '积分'                
                    u_record(ytime,cid,tid)
                    u_jfen(jf)
                    c_input.value = c_input.value + bb
                    globals()['hd'] = 0 #答对重新出题
                    c_label2.text = '复习:' + c_input.value
                    globals()['jj'],globals()['dan'],globals()['hd'],globals()['cid'],globals()['tid'],cvalue=settm(nd)
                    bb = ''
                    globals()['cuo'] = 0
                    c_input.value = cvalue
                    globals()['begintime'] = time()
                else:
                    c_label1.text = '答错了,本次扣2分,你只答对了1个数字,请输入下一个数字'
                    globals()['cuo'] += 1
                    u_cuo(cid,tid)
                    jf = -2
                    u_jfen(jf)
                    #globals()['hd'] = 2
            elif dan ==100:
                dan2 = 0
                if str(dan2) == bb:
                    c_input.value = c_input.value + bb
                    c_label1.text = '你又答对了1个数字,请输入下一个数字'
                    globals()['hd'] = 3
                else:
                    c_label1.text = '你答错了,继续答题,本次扣2分'
                    globals()['cuo'] += 1
                    u_cuo(cid,tid)
                    jf = -2
                    u_jfen(jf)
                    
        if is_number(bb) and hd == 1:
            if dan < 10:
                ytime = int((time() - begintime) * 1000)
                if dan == int(bb):
                    jf = jf_ytime(ytime)
                    c_label1.text = '你答对了' + ',本题取得' + str(jf) + '积分'                
                    u_record(ytime,cid,tid)
                    u_jfen(jf)
                    c_input.value = c_input.value + bb
                    c_label2.text = '复习:' + c_input.value
                    globals()['jj'],globals()['dan'],globals()['hd'],globals()['cid'],globals()['tid'],cvalue=settm(nd)
                    bb = ''
                    globals()['cuo'] = 0
                    c_input.value = cvalue
                    globals()['begintime'] = time()
                else:
                    c_label1.text = '你答错了,继续答题,本次扣2分'
                    globals()['cuo'] += 1
                    u_cuo(cid,tid)
                    jf = -2
                    u_jfen(jf)
            elif dan >= 10 and dan < 100:
                dan1 = int(str(dan)[:1])
                #print(dan1)
                if dan1 == int(bb):
                    c_label1.text = '你答对了1个数字,请输入下一个数字'
                    c_input.value = c_input.value + bb
                    globals()['hd'] = 2
                else:
                    globals()['cuo'] += 1
                    u_cuo(cid,tid)
                    jf = -2
                    u_jfen(jf)
                #    c_label1.text = '你答错了,继续答题'                
            elif dan == 100:
                dan1 = 1
                if dan1 == int(bb):
                    c_input.value = c_input.value + bb
                    c_label1.text = '你答对了1个数字,请输入下一个数字'
                    globals()['hd'] = 2
                else:
                    globals()['cuo'] += 1
                    u_cuo(cid,tid)
                    jf = -2
                    u_jfen(jf)

    aaa = '7 8 9 + 4 5 6 - 1 2 3 × 0 易 难 ÷'.split()
    #print(aaa) 用字符串变为数组,这样代码比较简
    for i in range(1,17):
        names['button_' + str(i)] = toga.Button(aaa[i-1], on_press=partial(bt1, aaa[i-1]),style=Pack(font_size=25))
    #初始界面
    # 设置组件样式和布局
    c_box.add(c_input)
    box.add(c_box)
    for i in range(1,5):
        b1_box.add(names['button_' + str(i)])
    for i in range(5,9):
        b2_box.add(names['button_' + str(i)])
    for i in range(9,13):
        b3_box.add(names['button_' + str(i)])
    for i in range(13,17):
        b4_box.add(names['button_' + str(i)])
    box.add(b1_box)
    box.add(b2_box)
    box.add(b3_box)
    box.add(b4_box)
    box.add(c_label)
    box.add(c_label1)
    box.add(c_label2)
    box.add(c_label3)
    # 设置 outer box 和 inner box 的样式
    box.style.update(direction=COLUMN, padding=5)
    b1_box.style.update(direction=ROW, padding=1)
    b2_box.style.update(direction=ROW, padding=1)
    b3_box.style.update(direction=ROW, padding=1)
    b4_box.style.update(direction=ROW, padding=1)
    c_box.style.update(direction=ROW, padding=5)

    # 设置单个组件的样式
    c_input.style.update(width=345, flex=1)

    # button.style.update(padding=15)
    c_label.style.update(width=345, padding_left=4)
    c_label1.style.update(width=345, padding_left=4)
    c_label2.style.update(width=345, padding_left=4)
    c_label3.style.update(width=345, padding_left=4)
    for i in range(1,17):
        names['button_' + str(i)].style.update(width=85, height=85, padding=1)
    return box
def plays(t1,tfh1,t2,tfh2,tdan):
    thread = threading.Thread(target=bfsz, args=(t1,tfh1,t2,tfh2,tdan,))
    thread.daemon = True
    thread.start()
#播放算式
def pfh(fh):
    thread = threading.Thread(target=bffh, args=(fh,))
    thread.daemon = True
    thread.start()
    #播放符号
def pnum(num):
    thread = threading.Thread(target=bfnum, args=(num,))
    thread.daemon = True
    thread.start()
    #播放数字
def main():
    return toga.App("千纬数学(读题版)", "org.qwsx", startup=build)

if __name__ == "__main__":
    main().main_loop()

app也上传了

  • 20
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值