这个程序有什么问题。我得到名称错误:
NameError:name' sum1'未定义
import os
from kivy.app import App
from kivy.uix.filechooser import FileChooserListView
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.popup import Popup
from kivy.lang.builder import Builder
Builder.load_string('''
<WarningPopup@Popup>:
title: 'Warning'
size_hint: None, None
size: 400, 200
BoxLayout:
orientation: "vertical"
Label:
text: 'Do you really want to delete this element?'
BoxLayout:
size_hint_y: 0.3
Button:
text: "Cancel"
on_release: root.dismiss()
Button:
text: "Accept"
on_release:
root.parent_inst.delete()
root.dismiss()
''')
class WarningPopup(Popup):
def __init__(self, parent_inst, *args, **kwargs):
super(WarningPopup, self).__init__(*args, **kwargs)
self.parent_inst = parent_inst
class MainWindow(BoxLayout):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.orientation = "vertical"
self.fichoo = FileChooserListView()
self.popup = WarningPopup(self)
btn_delete = Button(text="Delete", on_release=self.popup.open, size_hint_y=0.1)
self.add_widget(self.fichoo)
self.add_widget(btn_delete)
def delete(self, *args):
os.remove(self.fichoo.selection[0])
self.fichoo._update_files()
class ExampleApp(App):
def build(self):
return MainWindow()
if __name__ == "__main__":
ExampleApp().run()
答案 0 :(得分:0)
你在return语句中有错误。
return self.sum1(self.a, self.b)
答案 1 :(得分:0)
只要你在课堂上,就必须:
class sum:
def sum1(self,a,b):
self.c=a+b
return self.c
def init(self,a,b):
self.a=a
self.b=b
return self.sum1(self.a,self.b)
d=sum()
a=6
b=7
h=d.init(a,b)
print(h)
您没有在sum1
的{{1}}调用前加self
:
return self.sum1(self.a,self.b)