Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我应该使用哪个模块使用蓝牙制作Kivy应用程序?_Python_Bluetooth_Kivy - Fatal编程技术网

Python 我应该使用哪个模块使用蓝牙制作Kivy应用程序?

Python 我应该使用哪个模块使用蓝牙制作Kivy应用程序?,python,bluetooth,kivy,Python,Bluetooth,Kivy,我想在python kivy中使用蓝牙创建一个游戏,但我不知道这是否可行。我应该使用哪些模块来创建一个kivy应用程序,我可以在其中使用Bluetooth既然您正在尝试在Android上使用Bluetooth制作一个游戏,这是一个Java类,那么您应该使用Pyjnius模块,它允许python应用程序使用Java类 文件 您可以像这样使用Pyjnius: 从jnius导入自动类 BluetoothAdapter=自动类“android.bluetooth.BluetoothAdapter” Bl

我想在python kivy中使用蓝牙创建一个游戏,但我不知道这是否可行。我应该使用哪些模块来创建一个kivy应用程序,我可以在其中使用Bluetooth

既然您正在尝试在Android上使用Bluetooth制作一个游戏,这是一个Java类,那么您应该使用Pyjnius模块,它允许python应用程序使用Java类

文件

您可以像这样使用Pyjnius:

从jnius导入自动类 BluetoothAdapter=自动类“android.bluetooth.BluetoothAdapter” BluetoothDevice=自动类'android.bluetooth.BluetoothDevice' BluetoothSocket=自动类'android.bluetooth.BluetoothSocket' UUID=自动类'java.util.UUID' def get_套接字_流名称: 配对设备=BluetoothAdapter.getDefaultAdapter.getBondedDevices.toArray 套接字=无 对于成对_设备中的设备: 如果device.getName==名称: socket=device.createrFComSocketToServiceRecord UUID.fromString00001101-0000-1000-8000-00805F9B34FB recv_stream=socket.getInputStream send_stream=socket.getOutputStream 打破 socket.connect 返回接收流,发送流 类别蓝牙: 定义初始设备名称: self.recv\u stream,self.send\u stream=get\u socket\u streamname设备 def sendself,cmd: self.send_stream.write'{}\n'.formatcmd self.send\u stream.flush