我正在尝试创建一个 python 文件,该文件将向包含 .txt 文件的目录发送垃圾邮件。
我决定开始使用 Tkinter,但是每当我尝试输入一个数字时,我都会收到此错误消息 "TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'"
我正在使用的代码是:
from tkinter import *
top = Tk()
top.geometry("400x250")
Amount = Label(top, text = "Amount").place(x = 30,y = 50)
def spam():
for i in range(int(e1)):
print(i)
sbmitbtn = Button(top, text = "Submit",activebackground = "pink", activeforeground = "blue",command=spam).place(x = 30, y = 170)
e1 = Entry(top).place(x = 80, y = 50)
top.mainloop()
Run Code Online (Sandbox Code Playgroud)
我已经厌倦了切换到
for i in range(int(e1)):,
for i in range(str(e1)):
但随后收到错误消息:
"TypeError: 'str' object cannot be interpreted as an integer"
Run Code Online (Sandbox Code Playgroud)
任何帮助都是好的帮助
使用get()方法获取Entry的值。例子:
def spam():
for i in range(int(e1.get())):
print(i)
Run Code Online (Sandbox Code Playgroud)
并且不要将条目放置/打包在同一行中:
错误的:
e1 = Entry(top).place(x = 80, y = 50)
Run Code Online (Sandbox Code Playgroud)
正确的:
e1 = Entry(top)
e1.place(x = 80, y = 50)
Run Code Online (Sandbox Code Playgroud)