嗯,我在kivy中使用“id”时遇到了一个问题。你知道吗
from twisted.internet import reactor, protocol
from twisted.protocols.basic import LineReceiver
class User(protocol.Protocol):
def connectionMade(self):
self.transport.write("hey brother")
def dataReceived(self, data):
print (data)
class ChatClientFActory(protocol.ClientFactory):
protocol=User
def __init__(self,app):
self.app=app
class ClientFactory(protocol.ClientFactory):
def buildProtocol(self, addr):
return User()
def run():
reactor.connectTCP("localhost",8000,ClientFactory())
reactor.run()
from kivy.app import App
from kivy.uix.relativelayout import RelativeLayout
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen, ScreenManager
Builder.load_file("chat.kv")
Builder.load_file("chat2.kv")
class User1(Screen):
pass
class User2(Screen):
pass
s=ScreenManager()
s.add_widget(User1(name="start"))
s.add_widget(User2(name="let's_chat"))
class ChatApp(App):
def connect(self):
print(self.root.ids.message.text)
self.parent.current="let's_chat"
def build(self):
return s
if __name__=="__main__":
ChatApp().run()
当我使用“self.root.ids.消息.text,它总是显示“'super'对象没有属性'getattr”。我找了很多遍,但没有找到解决办法。下面是的kv文件本文件:你知道吗
<User1>:
RelativeLayout:
TextInput:
text:
pos_hint:{"center_x":.5,"center_y":.5}
size_hint: .3, .2
Button:
text:"start"
pos_hint:{"x":0,"bottom":0}
size_hint: .3, .2
on_press:
app.connect()
请帮忙。你知道吗
ScreenManager不是ChatApp的父级。您需要找到一种正确引用小部件的方法。这是一个可能的解决方案的草图。虽然没有测试!或者,尝试扩展ScreenManager,然后使用StringProperty、ObjectProperty和ids。希望它有帮助,虽然没有测试。如果您有一个没有
twisted
的独立示例,我可以帮助您更好地测试我的解决方案。你知道吗Python
千伏
这里是整个程序没有扭曲它非常简单,但我有困难,从一个kv按钮调用方法。你知道吗
你知道吗聊天.py你知道吗
你知道吗千伏你知道吗
2.2千伏
其显示错误:
对不起,如果我做了蠢事。我想我在使用app方法调用任何函数时都有困难。如果是,请告诉我如何使用“self.app软件". 你知道吗
相关问题 更多 >
编程相关推荐