单击Android上的TextInput后,Kivy应用程序崩溃
我尝试为一个测验游戏构建一个应用程序,但是在我单击输入字段后立即失败。当我在Vscode中打开它时,它可以正常工作,然后通过Digitaocean Linux Server Ubuntu 20.04导出它。我尝试删除BoxLayoutexample:从KV文件的顶部删除,但没有帮助。
mynew.kv
<BoxLayoutExample>:
orientation:"vertical"
Label:
size_hint:1,.5
text:"Enter private IP address of host:"
id:label1
TextInput:
size_hint:1,.5
id:input_ip
multiline:False
Label:
size_hint:1,.5
text:"Enter port number (10000-65535):"
id:label2
TextInput:
size_hint:1,.5
id:input_port
multiline:False
Label:
size_hint:1,.5
text:"Enter team name:"
id:label3
TextInput:
size_hint:1,.5
id:input_team_name
multiline:False
Label:
size_hint:1,.5
text:"Your score is: 0"
id:label_score
Button:
text:"connect"
id:button
on_press: root.click()
#size:"40dp","40dp"
size_hint:1,4.5
pos_hint:{"center_x":0.5}
main.py
import socket,threading
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
class BoxLayoutExample(BoxLayout):
score = 0
pos = 0
i = 0
name = 0
TCP_IP = ""
BUFFER_SIZE = 1024
TCP_PORT = 0
s=0
def click(self):
if self.ids.button.text == "Raise hand":
self.s.send(self.name.encode("ascii"))
elif self.name != "":
self.name = self.ids.input_team_name.text
self.TCP_PORT = int(self.ids.input_port.text)
self.TCP_IP = self.ids.input_ip.text
self.ids.input_ip.size_hint = (0, 0)
self.ids.input_team_name.size_hint = (0, 0)
self.ids.input_port.size_hint = (0, 0)
self.ids.label1.size_hint = (0, 0)
self.ids.label2.size_hint = (0, 0)
self.ids.label3.size_hint = (0, 0)
self.ids.button.text = "Raise hand"
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.s.connect((self.TCP_IP, self.TCP_PORT))
self.s.send(self.name.encode("ascii"))
thread2=threading.Thread(target=receive,args=(self,))
thread2.start()
class mynewApp(App): # App should be at end of class
def build(self):
return BoxLayoutExample()
def receive(other):
while 1:
BoxLayoutExample.score = other.s.recv(
BoxLayoutExample.BUFFER_SIZE).decode("ascii")
BoxLayoutExample.pos = other.s.recv(
BoxLayoutExample.BUFFER_SIZE).decode("ascii")
other.ids.label_score.text = f"Your score is: {other.score} and you are on {other.pos}. position"
mynewApp().run()
Android Studio LogCat的最后几行:
2022-06-06 10:41:37.640 24504-24533/org.test.myapp I/python: [INFO ] [Base ] Leaving application in progress...
2022-06-06 10:41:37.640 24504-24533/org.test.myapp I/python: Traceback (most recent call last):
2022-06-06 10:41:37.640 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/app/main.py", line 58, in <module>
2022-06-06 10:41:37.640 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/kivy/app.py", line 955, in run
2022-06-06 10:41:37.641 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/kivy/base.py", line 574, in runTouchApp
2022-06-06 10:41:37.641 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/kivy/base.py", line 339, in mainloop
2022-06-06 10:41:37.642 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/kivy/base.py", line 383, in idle
2022-06-06 10:41:37.642 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/kivy/base.py", line 334, in dispatch_input
2022-06-06 10:41:37.642 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/kivy/base.py", line 302, in post_dispatch_input
2022-06-06 10:41:37.642 24504-24533/org.test.myapp I/python: File "kivy/_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
2022-06-06 10:41:37.642 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/kivy/uix/textinput.py", line 1674, in on_touch_up
2022-06-06 10:41:37.642 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/kivy/uix/textinput.py", line 249, in __init__
2022-06-06 10:41:37.643 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/kivy/uix/widget.py", line 1167, in get_window_matrix
2022-06-06 10:41:37.643 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/kivy/uix/widget.py", line 1152, in _apply_transform
2022-06-06 10:41:37.643 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/kivy/uix/widget.py", line 1150, in _apply_transform
2022-06-06 10:41:37.643 24504-24533/org.test.myapp I/python: TypeError: to_window() argument after * must be an iterable, not int
2022-06-06 10:41:37.643 24504-24533/org.test.myapp I/python: Python for android ended.
2022-06-06 10:41:37.676 24504-24520/org.test.myapp W/System: A resource failed to call close.
2022-06-06 10:41:37.698 24504-24538/org.test.myapp A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xf1fe4a3a48 in tid 24538 (InsetsAnimation), pid 24504 (org.test.myapp)```
I tried to build an app for one quiz game but it failed immediately after I click the input field. When I opened it in vscode it worked just fine then I exported it through digitaocean Linux server ubuntu 20.04. I tried removing BoxLayoutExample: from top of kv file but it didn't help.
mynew.kv
<BoxLayoutExample>:
orientation:"vertical"
Label:
size_hint:1,.5
text:"Enter private IP address of host:"
id:label1
TextInput:
size_hint:1,.5
id:input_ip
multiline:False
Label:
size_hint:1,.5
text:"Enter port number (10000-65535):"
id:label2
TextInput:
size_hint:1,.5
id:input_port
multiline:False
Label:
size_hint:1,.5
text:"Enter team name:"
id:label3
TextInput:
size_hint:1,.5
id:input_team_name
multiline:False
Label:
size_hint:1,.5
text:"Your score is: 0"
id:label_score
Button:
text:"connect"
id:button
on_press: root.click()
#size:"40dp","40dp"
size_hint:1,4.5
pos_hint:{"center_x":0.5}
main.py
import socket,threading
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
class BoxLayoutExample(BoxLayout):
score = 0
pos = 0
i = 0
name = 0
TCP_IP = ""
BUFFER_SIZE = 1024
TCP_PORT = 0
s=0
def click(self):
if self.ids.button.text == "Raise hand":
self.s.send(self.name.encode("ascii"))
elif self.name != "":
self.name = self.ids.input_team_name.text
self.TCP_PORT = int(self.ids.input_port.text)
self.TCP_IP = self.ids.input_ip.text
self.ids.input_ip.size_hint = (0, 0)
self.ids.input_team_name.size_hint = (0, 0)
self.ids.input_port.size_hint = (0, 0)
self.ids.label1.size_hint = (0, 0)
self.ids.label2.size_hint = (0, 0)
self.ids.label3.size_hint = (0, 0)
self.ids.button.text = "Raise hand"
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.s.connect((self.TCP_IP, self.TCP_PORT))
self.s.send(self.name.encode("ascii"))
thread2=threading.Thread(target=receive,args=(self,))
thread2.start()
class mynewApp(App): # App should be at end of class
def build(self):
return BoxLayoutExample()
def receive(other):
while 1:
BoxLayoutExample.score = other.s.recv(
BoxLayoutExample.BUFFER_SIZE).decode("ascii")
BoxLayoutExample.pos = other.s.recv(
BoxLayoutExample.BUFFER_SIZE).decode("ascii")
other.ids.label_score.text = f"Your score is: {other.score} and you are on {other.pos}. position"
mynewApp().run()
Few last lines from android studio logcat:
2022-06-06 10:41:37.640 24504-24533/org.test.myapp I/python: [INFO ] [Base ] Leaving application in progress...
2022-06-06 10:41:37.640 24504-24533/org.test.myapp I/python: Traceback (most recent call last):
2022-06-06 10:41:37.640 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/app/main.py", line 58, in <module>
2022-06-06 10:41:37.640 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/kivy/app.py", line 955, in run
2022-06-06 10:41:37.641 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/kivy/base.py", line 574, in runTouchApp
2022-06-06 10:41:37.641 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/kivy/base.py", line 339, in mainloop
2022-06-06 10:41:37.642 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/kivy/base.py", line 383, in idle
2022-06-06 10:41:37.642 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/kivy/base.py", line 334, in dispatch_input
2022-06-06 10:41:37.642 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/kivy/base.py", line 302, in post_dispatch_input
2022-06-06 10:41:37.642 24504-24533/org.test.myapp I/python: File "kivy/_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
2022-06-06 10:41:37.642 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/kivy/uix/textinput.py", line 1674, in on_touch_up
2022-06-06 10:41:37.642 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/kivy/uix/textinput.py", line 249, in __init__
2022-06-06 10:41:37.643 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/kivy/uix/widget.py", line 1167, in get_window_matrix
2022-06-06 10:41:37.643 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/kivy/uix/widget.py", line 1152, in _apply_transform
2022-06-06 10:41:37.643 24504-24533/org.test.myapp I/python: File "/root/enviroments/kivy_lab/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/myapp/arm64-v8a/kivy/uix/widget.py", line 1150, in _apply_transform
2022-06-06 10:41:37.643 24504-24533/org.test.myapp I/python: TypeError: to_window() argument after * must be an iterable, not int
2022-06-06 10:41:37.643 24504-24533/org.test.myapp I/python: Python for android ended.
2022-06-06 10:41:37.676 24504-24520/org.test.myapp W/System: A resource failed to call close.
2022-06-06 10:41:37.698 24504-24538/org.test.myapp A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xf1fe4a3a48 in tid 24538 (InsetsAnimation), pid 24504 (org.test.myapp)```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现名称POS是在Kivy中定义的,因此导入Internet App起作用后会导致错误。
I found out that name pos was defined in kivy so that caused error after importing INTERNET app works.