0
我想在客戶端&服務器基礎上使用kivy & python進行文件選擇器的代碼...其餘部分代碼工作正常,但給出的部分給出的屬性錯誤爲「'ClientScreen'has沒有屬性「openfile_from_filechooser」」Python&Kivy屬性錯誤:
在這部分我想提出的錯誤...我有搜索,我怎麼能解決屬性錯誤,但沒有工作的...
class ClientScreen(Screen):
def __init__(self, **kwargs):
super(ClientScreen, self).__init__(**kwargs)
def openfile(self, path, filename):
f = open(os.path.join(path, filename[0]))
print f.read()
#self.clear_widgets()
def selected(self, filename):
print "selected: %s" % filename[0]
def openfile_from_filechooser(self, filechooser):
self.openfile(filechooser.path, filechooser.selection)
def selected_from_filechooser(self, filechooser):
self.selected(filechooser.selection)
def terminate(instance):
sys.exit()
def data(instance):
global IP
global conn
global host
global port
global address
print("Inside Data")
self.clear_widgets()
print("Inside File Operation")
button1 = Button(text = 'Open',size_hint = (None,None),pos = (0,0))
self.add_widget(button1)
button1.bind(on_release=partial(self.openfile_from_filechooser, filechooser))
button2 = Button(text = 'Send',size_hint = (None,None),pos = (100,0))
self.add_widget(button2)
#button2.bind(on_release=partial(self.selected_from_filechooser, filechooser))
def connection(instance):
global IP
global conn
global host
global port
global address
self.clear_widgets()
text = IP.text
print(text)
self.add_widget(Label (text = text))
print "Imported socket module"
print "Imported sys module used for termination condition"
conn = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
print('Socket created')
host = IP.text
print "Host Name:",host
port = 8000
print "Port value accessed",port
try:
self.clear_widgets()
address = (host,port)
print('Value of Address:',address)
print('Trying to connect...')
print('Initiating TCP server connection')
self.add_widget(Label(text = 'Connected....Press Next To Proceed...'))
button1 = Button(text = 'Next',size_hint = (None,None),pos = (0,0))
self.add_widget(button1)
button1.bind(on_press = data)
except socket.error as msg:
self.clear_widgets()
self.add_widget(Label(text = 'Sorry...Unable to create socket...press Finish to terminate...'))
button2 = Button(text = 'Finish',size_hint = (None,None),pos = (0,0))
self.add_widget(button2)
button2.bind(on_press = terminate)
print('Socket not created')
def ip_addr(instance):
global IP
self.clear_widgets()
self.add_widget(Label (text = "Enter the destination device's IP address"))
IP = TextInput(multiline=False, size_hint = (1,0.1), pos = (0,200))
print(IP.text)
self.add_widget(IP)
button1 = Button(text = 'Enter',size_hint = (None,None),pos = (0,0))
self.add_widget(button1)
button1.bind(on_press = connection)
global IP
self.add_widget(Label(text = 'Working as Client...Press Next to proceed'))
button1 = Button(text = 'Next',size_hint = (None,None),pos = (0,0))
self.add_widget(button1)
button1.bind(on_press = ip_addr)
這將是很有益如果有人能指出我的錯誤在哪裏&我該如何糾正這個錯誤
我再次對它進行縮進......但仍然不起作用 – 2015-02-24 04:24:36
我曾經叫超級(ClientScreen,self).__ init __(** kwargs),但是我沒有發佈整個ClientScreen類。由於ClientScreen類的其他部分工作正常......我只是在添加之前提到的代碼後纔會出錯 – 2015-02-24 08:47:43
發佈您的新代碼。 – inclement 2015-02-24 10:48:44