微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

sqlalchemy.exc.NoResultFound:需要时找不到行,Tkinter回调中的异常

如何解决sqlalchemy.exc.NoResultFound:需要时找不到行,Tkinter回调中的异常

我编写了以下代码。它是执行一些基本化学操作的基本乌龟。我一直收到这个错误

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\Arnav\AppData\Local\Programs\Python\python39\lib\tkinter\__init__.py",line 1892,in __call__
    return self.func(*args)
  File "C:\Users\Arnav\AppData\Local\Programs\Python\python39\lib\turtle.py",line 674,in eventfun
    fun(x,y)
  File "c:\Users\Arnav\Desktop\VS Code\Python\periodicTable.py",line 41,in getCoords
    return optionClick(x,line 152,in optionClick
    atomicNum,name = getAtomicNumber('si')
  File "c:\Users\Arnav\Desktop\VS Code\Python\periodicTable.py",line 9,in getAtomicNumber
    userElement = mendeleev.element(element)
  File "C:\Users\Arnav\AppData\Local\Programs\Python\python39\lib\site-packages\mendeleev\mendeleev.py",line 64,in element
    return _get_element(ids)
  File "C:\Users\Arnav\AppData\Local\Programs\Python\python39\lib\site-packages\mendeleev\mendeleev.py",line 81,in _get_element
    return session.query(Element).filter(Element.symbol == str(ids)).one()
  File "C:\Users\Arnav\AppData\Local\Programs\Python\python39\lib\site-packages\sqlalchemy\orm\query.py",line 2809,in one
    return self._iter().one()
  File "C:\Users\Arnav\AppData\Local\Programs\Python\python39\lib\site-packages\sqlalchemy\engine\result.py",line 1374,in one
    return self._only_one_row(
  File "C:\Users\Arnav\AppData\Local\Programs\Python\python39\lib\site-packages\sqlalchemy\engine\result.py",line 561,in _only_one_row       
    raise exc.noresultFound(
sqlalchemy.exc.noresultFound: No row was found when one was required

这是我的代码

import turtle
from mendeleev import *
from turtle import *
import time



def getAtomicNumber(element):   
    userElement = mendeleev.element(element)    
    return userElement.atomic_number,userElement.name


def getElementName(element):
    userElement = mendeleev.element(element)
    
    return userElement.name
def getElementdiscoverer(element):
    userElement = mendeleev.element(element)
    return userElement.name,userElement.discoverers
def getElementElectrons(element):
    userElement = mendeleev.element(element)

    return userElement.electrons,userElement.name
def getIonizationEnergy(element):
    userElement = mendeleev.element(element)

    return userElement._ionization_energies,userElement.name
def getMassNumber(element):
    userElement = mendeleev.element(element)

    return userElement.mass_number,userElement.name
def getNameOrigin(element):
    userElement = mendeleev.element(element)

    return userElement.name_origin
def getEConfiguration(element):
    userElement = mendeleev.element(element)

    return userElement.econf,userElement.name
def getCoords(x,y):
    return optionClick(x,y)
def optionClick(x,y):
   
    
    print(x,y)
    writer = turtle.Turtle()
    writer.speed(0)
    writer.color('white')
    writer.penup()
    writer.hideturtle()
    writer.goto(0,-200)




    if -310<x<310 and 130>y>90:
        atomicNum,name = getAtomicNumber('si')
        writer.write(f'{name} has an atomic number of {atomicNum}')
        
    elif -310<x<310 and 90>=y>75:
        getElementName('si')
    elif -310<x<310 and 75>y>50:
        name,discoverer = getElementdiscoverer('si')


window = turtle.Screen()
window.setup(width=800,height=600)
window.title('Chemistry Tool')
window.bgcolor('black')
window.tracer(0)

pen = turtle.Turtle()
pen.speed(0)
pen.color('red')
pen.penup()
pen.hideturtle()
pen.goto(0,200)
pen.write("Welcome to the Chemistry Tool",align="center",font=('Courier New',26,'bold'))


choose = turtle.Turtle()
choose.speed(0)
choose.color('green')
choose.penup()
choose.hideturtle()
choose.goto(0,150)
choose.write("Please choose a function from the following:",16,'normal'))

choice_1 = turtle.Turtle()
choice_1.speed(0)
choice_1.color('blue')
choice_1.penup()
choice_1.hideturtle()
choice_1.goto(0,100)
choice_1.write("1. Get Atomic Number",15,'normal'))


choice_2 = turtle.Turtle()
choice_2.speed(0)
choice_2.color('yellow')
choice_2.penup()
choice_2.hideturtle()
choice_2.goto(0,75)
choice_2.write("2. Get Name of Element",'normal'))

choice_3 = turtle.Turtle()
choice_3.speed(0)
choice_3.color('purple')
choice_3.penup()
choice_3.hideturtle()
choice_3.goto(0,50)
choice_3.write("3. Get discoverer of Element",'normal'))

choice_4 = turtle.Turtle()
choice_4.speed(0)
choice_4.color('pink')
choice_4.penup()
choice_4.hideturtle()
choice_4.goto(0,25)
choice_4.write("4. Get Number of Electrons in Element",'normal'))


choice_5 = turtle.Turtle()
choice_5.speed(0)
choice_5.color('red')
choice_5.penup()
choice_5.hideturtle()
choice_5.goto(0,0)
choice_5.write("5. Get Ionization Energy of Element",'normal'))

choice_6 = turtle.Turtle()
choice_6.speed(0)
choice_6.color('green')
choice_6.penup()
choice_6.hideturtle()
choice_6.goto(0,-25)
choice_6.write("6. Get Mass Number of Element",'normal'))


choice_7 = turtle.Turtle()
choice_7.speed(0)
choice_7.color('blue')
choice_7.penup()
choice_7.hideturtle()
choice_7.goto(0,-50)
choice_7.write("7. Get Name Origin",'normal'))

choice_8 = turtle.Turtle()
choice_8.speed(0)
choice_8.color('yellow')
choice_8.penup()
choice_8.hideturtle()
choice_8.goto(0,-75)
choice_8.write("8. Get electronic Configuration",'normal'))





        

        


        
            







if __name__ == '__main__':
    while True:
        window.update()
        window.onscreenclick(getCoords)

我是 python 龟库的初学者。我认为错误基本上是因为while循环。如果有更好的方法在乌龟中设计菜单,请也发布。

编辑:只有当我点击指定给每个按钮的区域时才会发生错误

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。