kivy __init__需要1个参数

时间:2016-05-02 11:38:55

标签: python-3.x kivy

我有一个kivy的问题:(你能帮我解决一下吗?

import kivy
import socket
import threading

kivy.require('1.9.1') # replace with your current kivy version !

s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(('localhost',9999))

from kivy.app import App
from kivy.uix.label import Label

duyuru=""

def readData():
    data = s.recv(1024)
    if data:
        duyuru=data
    else:
        duyuru="Henüz duyuru yok!"

class MyApp(App):

    def build(self):
        t1 = threading.Thread(target=readData)
        t1.start()
        return Label(duyuru)
if __name__ == '__main__':
    MyApp().run()

它给我一个错误说:"类型错误:__init__需要1个位置参数但是2个被给出"。 kivy窗口打开但停止运行:(

回溯:

[INFO           ] [Logger      ] Record login 
C:\Users\Beatless27\.kivy\logs\kivy_16-05-02_40.txt
[INFO              ] [Kivy        ] v1.9.1
[INFO              ] [Python      ] v3.4.4 (v3.4.4:737efcadf5a6, Dec 20             2015, 19:28:18) [MSC v.1600 32 bit (Intel)]
[INFO              ] [Factory     ] 179 symbols loaded
[INFO              ] [Image       ] Providers: img_tex, img_dds, img_gif,     img_sdl2 (img_pil, img_ffpyplayer ignored)
[INFO              ] [Text        ] Provider: sdl2
[INFO              ] [OSC         ] using <thread> for socket
[INFO              ] [Window      ] Provider: sdl2
[INFO              ] [GL          ] GLEW initialization succeeded
[INFO              ] [GL          ] OpenGL version <b'3.3.0'>
[INFO              ] [GL          ] OpenGL vendor <b'NVIDIA Corporation'>
[INFO              ] [GL          ] OpenGL renderer <b'GeForce 9500         GT/PCIe/SSE2/3DNOW!'>
[INFO              ] [GL          ] OpenGL parsed version: 3, 3
[INFO              ] [GL          ] Shading version <b'3.30 NVIDIA via Cg compiler'>
[INFO              ] [GL          ] Texture max size <8192>
[INFO              ] [GL          ] Texture max units <32>
[INFO              ] [Window      ] auto add sdl2 input provider
[INFO              ] [Window      ] virtual keyboard not allowed, single     mode, not docked
 Traceback (most recent call last):
   File "AndroidClient.py", line 29, in <module>
     MyApp().run()
   File "C:\Python34\lib\site-packages\kivy\app.py", line 802, in run
     root = self.build()
   File "AndroidClient.py", line 27, in build
     return Label(duyuru)
 TypeError: __init__() takes 1 positional argument but 2 were given

1 个答案:

答案 0 :(得分:1)

使用Label(text=duyuru) - 它是关键字参数,而不是位置参数。