如何解决我的 SpamBot 项目有问题,即使我遵循了教程,它也没有做任何事情
我正在制作一个小型 SpamBot
项目。当我按下按钮时,它不起作用。我不确定是什么问题,因为我按照教程进行了操作,并且尝试了所有方法,但都不起作用。提前致谢。
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!',bg='SteelBlue1').grid()
e2 = Entry(root).grid()
b1 = Button(root,text='Execute',bg='SteelBlue1',command=spam).grid()
l3 = Label(root,text='Made By HareXD',bg='SteelBlue1').grid()
root.mainloop()
解决方法
grid
函数返回 None
,这就是您收到错误的原因:
AttributeError: 'NoneType' object has no attribute 'get'
要修复它,您应该替换该行:
e1 = Entry(root).grid()
对于这 2:
e1 = Entry(root)
e1.grid()
对 e2
条目执行相同操作。
完整的代码是:
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!',bg='SteelBlue1').grid()
e2 = Entry(root)
e2.grid()
b1 = Button(root,text='Execute',command=spam,bg='SteelBlue1').grid()
l3 = Label(root,text='Made By HareXD',bg='SteelBlue1').grid()
root.mainloop()
,
这个怎么样?网格是使用行和列。
l1 = Label(root,bg='SteelBlue1').grid(row=0,column=0)
e1 = Entry(root).grid(row=0,column=1)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。