-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
103 lines (82 loc) · 4.02 KB
/
Copy pathgui.py
File metadata and controls
103 lines (82 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import tkinter as tk
from tkinter import messagebox
import Spam
import threading
# Глобальная переменная для события остановки, чтобы функция stop() имела к нему доступ
stop_event = None
def start():
message = message_entry.get()
random_text = random_entry.get()
count_str = count_entry.get()
delay_str = delay_entry.get()
if not message or not count_str:
messagebox.showerror("Ошибка", "Поля 'Основное сообщение' и 'Количество сообщений' должны быть заполнены.")
return
# Отфильтровываем пустые элементы, чтобы избежать добавления лишних пробелов
random_messages = [word.strip() for word in random_text.split(',') if word.strip()]
try:
count = int(count_str)
if count <= 0:
messagebox.showerror("Ошибка", "Количество должно быть положительным числом.")
return
except ValueError:
messagebox.showerror("Ошибка", "Количество должно быть целым числом.")
return
try:
delay = float(delay_str)
if delay < 0:
messagebox.showerror("Ошибка", "Задержка не может быть отрицательной.")
return
except (ValueError, TypeError):
messagebox.showerror("Ошибка", "Задержка должна быть числом.")
return
# Блокируем кнопку, чтобы избежать повторных нажатий
global stop_event
stop_event = threading.Event()
start_button.config(state=tk.DISABLED)
stop_button.config(state=tk.NORMAL)
def update_status(text):
"""Безопасно обновляет статус из другого потока."""
status_label.config(text=text)
def spam_task_wrapper():
try:
# Передаем событие и функцию обратного вызова в задачу
Spam.start_spam(message, random_messages, count, delay, stop_event, lambda text: root.after(0, update_status, text))
finally:
# Возвращаем кнопку в активное состояние в основном потоке GUI
root.after(0, lambda: (
start_button.config(state=tk.NORMAL),
stop_button.config(state=tk.DISABLED)
))
# Запускаем задачу в отдельном потоке, чтобы не блокировать интерфейс
threading.Thread(target=spam_task_wrapper, daemon=True).start()
def stop():
"""Устанавливает событие для остановки спама."""
if stop_event:
stop_event.set()
root = tk.Tk()
root.title("Spammer")
root.geometry("400x350")
root.resizable(False, False)
title = tk.Label(root, text="Spam Sender", font=("Arial", 16))
title.pack(pady=10)
tk.Label(root, text="Основное сообщение").pack()
message_entry = tk.Entry(root, width=40)
message_entry.pack(pady=5)
tk.Label(root, text="Рандомные сообщения (через запятую)").pack()
random_entry = tk.Entry(root, width=40)
random_entry.pack(pady=5)
tk.Label(root, text="Количество сообщений").pack()
count_entry = tk.Entry(root, width=10)
count_entry.pack(pady=5)
tk.Label(root, text="Задержка между сообщениями (сек)").pack()
delay_entry = tk.Entry(root, width=10)
delay_entry.insert(0, "0.5") # Значение по умолчанию
delay_entry.pack(pady=5)
start_button = tk.Button(root, text="Начать спам", width=20, command=start)
start_button.pack(pady=10)
stop_button = tk.Button(root, text="Остановить", width=20, command=stop, state=tk.DISABLED)
stop_button.pack()
status_label = tk.Label(root, text="", fg="blue")
status_label.pack(pady=10)
root.mainloop()