我不明白为什么在运行代码时出现此类错误。我已经多次检查了这一切,一切似乎都很好,代码仍然不想运行。
这是我的__main__.py
文件:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.properties import ObjectProperty # at top of file
class AccountDetailsForm(AnchorLayout):
server_box = ObjectProperty()
username_box = ObjectProperty()
password_box = ObjectProperty()
def login(self):
print(self.server_box.text)
print(self.username_box.text)
print(self.password_box.text)
class Orkiv(App):
pass
Orkiv().run()
这是我的orkiv.kv
文件:
AccountDetailsForm:
<AccountDetailsForm>:
anchor_y: "top"
server_box: server_input
username_box: username_input
password_box: password_input
BoxLayout:
orientation: "vertical"
height: "200dp"
size_hint_y: None
GridLayout:
cols: 2
row_default_height: "40dp"
row_force_default: True
spacing: "10dp"
padding: "10dp"
Label:
text: "Server" //THE ERROR SEEMS TO HAPPEN HERE
AccountDetailsTextInput:
id: server_input
Label:
text: "Username"
AccountDetailsTextInput:
id: username_input
Label:
text: "Password"
AccountDetailsTextInput:
password: True
id: password_input
Button:
size_hint_y: None
height: "40dp"
text: "Login"
on_press: root.login()
有什么想法吗?感谢。
答案 0 :(得分:3)
在orkiv.kv
文件中,将AccountDetailsTextInput
更改为TextInput
。
AccountDetailsForm:
<AccountDetailsForm>:
anchor_y: "top"
server_box: server_input
username_box: username_input
password_box: password_input
BoxLayout:
orientation: "vertical"
height: "200dp"
size_hint_y: None
GridLayout:
cols: 2
row_default_height: "40dp"
row_force_default: True
spacing: "10dp"
padding: "10dp"
Label:
text: "Server"
TextInput:
id: server_input
Label:
text: "Username"
TextInput:
id: username_input
Label:
text: "Password"
TextInput:
password: True
id: password_input
Button:
size_hint_y: None
height: "40dp"
text: "Login"
on_press: root.login()
该应用应该运行。请参阅下面的输出。
如果有帮助,请告诉我们。