attwad / python-osc

Open Sound Control server and client in pure python
The Unlicense
514 stars 106 forks source link

how can I put the received message to GUI? #149

Open zingshowba opened 2 years ago

zingshowba commented 2 years ago

I'm a python probie, I'm trying to put the message that I send from my phone to GUI, or use the message as an order to execute some command. But I CANT get the message out, please help me out.

import PySimpleGUI as sg from pythonosc.dispatcher import Dispatcher from pythonosc.osc_server import BlockingOSCUDPServer

ip = "192.168.0.108" port = 1337

def print_handler(address, *args): print(f"{address}: {args}")

def default_handler(address, *args): print(f"DEFAULT {address}: {args}") print(f":{args}")

dispatcher = Dispatcher() dispatcher.map("/something/*", print_handler) dispatcher.set_default_handler(default_handler)

trying to get the msg and print it out But it didn't work

msg = dispatcher.set_default_handler(print_handler)

print(f"testing{msg}")

server = BlockingOSCUDPServer((ip, port), dispatcher)

server.serve_forever()

layout = [[sg.Text('MetaBorder')], [sg.Text(size=(20,1), font= "Any 15", key="-OUT-")], [sg.Button("获取数据"), sg.Button("退出")] ]

window = sg.Window("Metaborder", layout, keep_on_top=True)

while True: event, values = window.read(timeout=1000) if event is None or event == "退出": break window["-OUT-"].update(msg)

window.close()

rizaru22 commented 1 year ago

have you found the way to put OSC message to Label (GUI) ?