如何修复'AttributeError:'Button1'对象没有属性'fn'

问题描述 投票:0回答:1

我想在PDF查看器中打开一本书,以创建Android图书库。当您按下按钮时,应打开带有所需PDF书籍的阅读器。但是,当您单击按钮时,会出现错误。AttributeError:“ Button1”对象没有属性“ fn”

我试图做点什么,但我不明白

Button1: 
    text:"Русский язык" 
    on_press:root.russ_yaz(self.fn) 
class SubjectsScreen10(Screen): 
    def russ_yaz(self): 
    self.fn = 'Дудников, А.В Русский язык.pdf' 
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查看器打开这本书

python kivy python-3.7
1个回答
0
投票

错误来自以下行:

on_press:root.russ_yaz(self.fn) 

按钮(即self)不具有属性fn。属性fn属于

class SubjectsScreen10(Screen): 

您需要致电russ_yaz(SubjectScreen10.fn)或移动

self.fn = 'Дудников, А.В Русский язык.pdf' 

到Button类

© www.soinside.com 2019 - 2024. All rights reserved.