Answer the question
In order to leave comments, you need to log in
How to solve the problem with the visibility of the root variable?
The essence of the script is simply to spam new windows with an image
from random import randint
import tkinter as tk
from PIL import ImageTk, Image
import telebot;
from time import sleep
bot = telebot.TeleBot('token');
def createNewWindow(root, img):
for i in range(100):
newWindow = tk.Toplevel(root)
labelExample = tk.Label(newWindow, image = img)
w = randint(0, newWindow.winfo_screenwidth())
h = randint(0, newWindow.winfo_screenheight())
newWindow.geometry('+{}+{}'.format(w, h))
labelExample.pack()
@bot.message_handler(content_types=['text'])
def get_command(message):
if message.text == "Start":
root = tk.Tk()
img = ImageTk.PhotoImage(Image.open('lol.png'))
createNewWindow(root, img)
root.mainloop()
elif message.text == "Stop":
root.destroy()
bot.polling(none_stop=True, interval=0)
Answer the question
In order to leave comments, you need to log in
@bot.message_handler(content_types=['text'])
def get_command(message):
if message.text == "Start":
root = tk.Tk()
img = ImageTk.PhotoImage(Image.open('lol.png'))
createNewWindow(root, img)
root.mainloop()
elif message.text == "Stop":
root.destroy()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question