O
O
Oleg2021-08-28 00:16:01
Python
Oleg, 2021-08-28 00:16:01

Can't make streams?

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, 'what to answer')

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

label1 = Label(root)
label1.configure(text = 'Scripts:')
label1.place(x = 0, y = 0, height = 20, widt = 300)

label2 = Label(root)
label2. configure(text = 'Your Token ')
label2.place(x = 0, y = 0, height = 20, widt = 500)

instruction = Label(root)
instruction.configure(text = 'In order to create your baht you I need my own group in VK')
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 = 'Start ', command = check ).place(x = 500, y = 400, widt = 300)

root.mainloop()

I insert a token, I write words in the script - I press start and here (I can’t solve with molasses)
error:
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/Oleg/Desktop/Test/main.py", line 77, in check
k = {f'{var[2]} : f,{var[1]}'}
IndexError: list index out of range

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg, 2021-10-07
@Oleg57rus

Hello everyone and thank you so much for helping with advice,
I launched it and it works
615f3a179ef7d303002797.png
now I will think about how to add pictures there

A
AntVlad, 2021-08-28
@AntVlad

k = {f'{var[2]} : f,{var[1]}'}
Maybe instead of var[2] var[0]? Actually, the error says that the index of the dictionary is greater than the last index.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question