I am making a mini SpamBot
project. When I press the button it doesn't work. I'm not sure what's the problem because I followed the tutorial and I tried everything and it doesn't work. Thanks in advance.
from tkinter import *
import pyautogui
import time
def spam():
spam_word = e1.get()
spam_quantity = e2.get()
e1.delete(0, END)
e2.delete(0, END)
count = 0
time.sleep(10)
while count <= (int(spam_quantity)):
pyautogui.typewrite(spam_word)
pyautogui.press('enter')
count += 1
# GUI
root = Tk()
root.title("SpamBot")
root.geometry("500x500")
root.resizable(False, False)
root.columnconfigure(0, weight=1)
root.configure(bg='SteelBlue1')
l1 = Label(root, text='Write a message that you want to send!', font='Consolas', bg='SteelBlue1').grid()
e1 = Entry(root).grid()
l2 = Label(root, text='Set the message quantity!', font='Consolas', bg='SteelBlue1').grid()
e2 = Entry(root).grid()
b1 = Button(root, text='Execute', font='Consolas', bg='SteelBlue1', command=spam).grid()
l3 = Label(root, text='Made By HareXD', font='Consolas', bg='SteelBlue1').grid()
root.mainloop()
The grid
function returns None
, that's why the you're getting the error:
AttributeError: 'NoneType' object has no attribute 'get'
To fix it, you should replace the line:
e1 = Entry(root).grid()
For this 2:
e1 = Entry(root)
e1.grid()
And do the same with the e2
entry.
The complete code would be:
from tkinter import *
import pyautogui
import time
def spam():
spam_word = e1.get()
spam_quantity = e2.get()
e1.delete(0, END)
e2.delete(0, END)
count = 0
time.sleep(10)
while count <= (int(spam_quantity)):
pyautogui.typewrite(spam_word)
pyautogui.press('enter')
count += 1
# GUI
root = Tk()
root.title("SpamBot")
root.geometry("500x500")
root.resizable(False, False)
root.columnconfigure(0, weight=1)
root.configure(bg='SteelBlue1')
l1 = Label(root, text='Write a message that you want to send!', font='Consolas', bg='SteelBlue1').grid()
e1 = Entry(root)
e1.grid()
l2 = Label(root, text='Set the message quantity!', font='Consolas', bg='SteelBlue1').grid()
e2 = Entry(root)
e2.grid()
b1 = Button(root, text='Execute', font='Consolas', command=spam,bg='SteelBlue1').grid()
l3 = Label(root, text='Made By HareXD', font='Consolas', bg='SteelBlue1').grid()
root.mainloop()
How about this? Grid is to use row and column.
l1 = Label(root, text='Write a message that you want to send!', font='Consolas', bg='SteelBlue1').grid(row=0, column=0)
e1 = Entry(root).grid(row=0, column=1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.