
Я пытаюсь сделать онлайн крестики-нолики, но вылетает ошибка
код:
from pywebio import start_server
from pywebio.input import *
from pywebio.output import *
from pywebio.session import run_async, run_js
import asyncio
chatmsgs = []
frty = " | | "
srty = " | | "
trty = " | | "
async def main():
global chatmsgs
put_markdown('крестики-нолики')
msgbox = output
put_scrollable(msgbox, height=300, keep_bottom=True)
ddd = await input('Вход', required=True, placeholder='Пароль')
if ddd == 'qwerty1234567890':
refsh_task = run_async(refresh_msg(msgbox))
while True:
data = await input_group("Ход",[
input(placeholder='(1о, 2x)', name='msg'),
actions(name='cmd', buttons=['Отправить', {'label':'Выйти из чата', 'type':'cancel'}])
], validate=lambda m: ('msg', "Введите читаемый ход!") if m["cmd"] == 'Отправить' and not m["msg"] else None)
if data is None:
break
if data == '1о':
frty[1] == "0"
msgbox.append(put_markdown(frty))
if data == '1х':
frty[1] == "X"
msgbox.append(put_markdown(frty))
if data == '2о':
frty[3] == "0"
msgbox.append(put_markdown(frty))
async def refresh_msg(msgbox):
global chatmsgs
last_idx = len(chatmsgs)
while True:
await asyncio.sleep(1)
for m in chatmsgs[last_idx]:
msgbox.append(put_markdown(f"{m[0]}: {m[1]}"))
if __name__ == "__main__":
start_server(main, debug=True, port=8080, cdn=False)