简体   繁体   English

Kivy 单击 android 上的 TextInput 后应用崩溃

[英]Kivy app crashes after clicking on TextInput on android

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.当我在 vscode 中打开它时,它工作得很好,然后我通过 digitaocean Linux 服务器 ubuntu 20.04 导出它。 I tried removing BoxLayoutExample: from top of kv file but it didn't help.我尝试从 kv 文件的顶部删除 BoxLayoutExample: 但它没有帮助。

mynew.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()

Few last lines from android studio logcat:来自 android 工作室 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 found out that name pos was defined in kivy so that caused error after importing INTE.NET app works.我发现名称 pos 是在 kivy 中定义的,因此在导入 INTE.NET 应用程序后会导致错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM