如何修复'NameError:未定义名称'russ_yaz''

时间:2019-11-09 14:57:17

标签: python pdf kivy python-3.7

我想在PDF查看器中打开一本书以创建Android图书库。当您按下按钮时,应打开带有所需PDF书籍的阅读器。但是,当您单击按钮时,会出现错误。 NameError:名称“ russ_yaz”未定义

我试图通过更改russ_yaz的位置来解决该问题,但没有任何改变。

class SubjectsScreen10(Screen):
    def russ_yaz(self):
        self.fn = 'Дудников, А.В Русский язык.pdf'
Button1:
    text:"Russian"
    on_press: russ_yaz(SubjectScreen10.fn)
if __name__ == '__main__':
    from sys import argv
    from kivy.base import runTouchApp
    from kivy.uix.scrollview import ScrollView

    if len(argv) > 1:
        fn = argv[1]
    root = PDFDocumentWidget(source=self.fn, cols=1)
    runTouchApp(root)
from tempfile import mkdtemp, mkstemp 
from shutil import rmtree 
from binascii import b2a_hex 
from os import write, close 
from threading import Thread 
from kivy.config import Config 
from pdfminer.pdfpage import PDFPage 
from pdfminer.pdfparser import PDFParser 
from pdfminer.converter import PDFPageAggregator 
from pdfminer.pdfdocument import PDFDocument, PDFNoOutlines 
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter 
from pdfminer.layout import ( 
LAParams, LTTextBox, LTTextLine, LTFigure, LTImage, LTChar, LTCurve, 
LTLine, LTRect, 
) 

from kivy.lang import Builder 
from kivy.clock import Clock 
import kivy.graphics 
from kivy.graphics import Mesh, Color 
from kivy.graphics.tesselator import Tesselator 

from kivy.uix.widget import Widget 
from kivy.uix.recycleview import RecycleView 
from kivy.uix.label import Label 
from kivy.uix.image import Image 
from kivy.uix.relativelayout import RelativeLayout 
from kivy.uix.boxlayout import BoxLayout 

from kivy.properties import ( 
StringProperty, ListProperty, NumericProperty, AliasProperty, 
DictProperty, ObjectProperty, BooleanProperty, ColorProperty, 
) 
from kivy.app import App 
from kivy.lang import Builder 
from kivy.uix.recycleview import RecycleView 
from kivy.uix.screenmanager import ScreenManager, Screen 
from kivy.uix.boxlayout import BoxLayout 
from kivy.uix.gridlayout import GridLayout 
from kivy.config import Config 

我想在pdf-viewer中打开这本书

1 个答案:

答案 0 :(得分:0)

  

我试图通过更改russ_yaz的位置来解决该问题,但没有任何改变。

大概你从来没有把它放在合适的位置。

Button1:
    text:"Russian"
    on_press: russ_yaz(SubjectScreen10.fn)

这段代码并不是试图从任何地方获取它,只是在本地名称空间中查找函数名称。这基本上是错误的,您需要确定特别定义的位置,然后从那里引用它。例如,如果您将russ_yaz用作Button1类的方法,则可以假设定义了SubjectScreen10 来进行self.russ_yaz(SubjectScreen10.fn)