Oleg57rus
@Oleg57rus
Пока ещё ученик

Не могу сделать потоки?

from tkinter import*
from tkinter.ttk import*
from vk_api.longpoll import VkLongPoll, VkEventType
import vk_api
import vk_api, json

class Bot():

def __init__(self, token, coms):
self.commands = coms
self.vk_session = vk_api.VkApi(token = token)
self.vk = self.vk_session.get_api()
self.longpoll = VkLongPoll(self.vk_session)


def answer(self, id, msg):
self.vk.messages.send(user_id = id,message = msg, rondom_id = 0)

def get_msg(self):
for event in self.longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW:
if event.to_me:

msg = event.text.lover_id
id = event.user_id

return id, msg

def work(self):
while True:
inf = self.get_msg()
if inf:
print(inf)
id = inf[0]
msg = inf[1]

if msg in self.commands:
self.answer(id, self.commands[msg])
else:
self.answer(id, 'хз чё ответить')

root = Tk()
root.geometry('800x500')
root.title('Boter')
root.resizable(False, False)
root.configure()

label1 = Label(root)
label1.configure(text = 'Сценарии:')
label1.place(x = 0, y = 0, height = 20, widt = 300)

label2 = Label(root)
label2. configure(text = 'Ваш Токен ')
label2.place(x = 0, y = 0, height = 20, widt = 500)

instruction = Label(root)
instruction.configure(text = 'Для того, чтобы создать своего бата вам нужна своя группа в вк')
instruction.place(x = 0, y = 41,height = 400, widt = 500)

body = StringVar()
token_entru = Entry(root, textvariable = body).place(x = 0, y = 21,height = 20, widt = 500)

main_slow = Text(root)
main_slow.place(x = 500, y = 21,height = 379, widt = 300)
main_com = {}
def check():
global main_slow, main_com, body
tok = str(body.get())
print(tok)

mas = main_slow.get(1.0, END).split('\n')
for i in mas:
if ':' in i:
var = i.split(':')
var[0] = var[0].strip()
var[1] = var[1].strip()
k = {f'{var[2]} : f,{var[1]}'}
main_com.update(k)
print(main_com)
botik = Bot(tok, main_com)
botik.work()
mbtn = Button(root, text = 'Старт', command = check ).place(x = 500, y = 400, widt = 300)

root.mainloop()

вставляю токен , пишу в сценарии слова - жму на старт и вот ( не могу решить с патоками )
ошибка:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Games\pun\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "c:/Users/Олег/Desktop/Test/main.py", line 77, in check
k = {f'{var[2]} : f,{var[1]}'}
IndexError: list index out of range
  • Вопрос задан
  • 172 просмотра
Решения вопроса 1
Oleg57rus
@Oleg57rus Автор вопроса
Пока ещё ученик
Всем привет и огромное спасибо, что помогали советами
всё я его запустил и он работает
615f3a179ef7d303002797.png

теперь буду думать как туда картинки добавлять
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
@AntVlad
k = {f'{var[2]} : f,{var[1]}'}
Может вместо var[2] var[0]? Собственно, ошибка гласит, что индекс словаря превышает последний индекс.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы