1

我一直在调查tkinker。每当我使用该get()函数从文本框中获取信息时,都会出现错误。当我使用该focus_set()功能时,我也会遇到同样的错误。

这是我的代码:

from tkinter import *

root = Tk()
root.title("Super Awsome Mega Pi")

Label(root, text="What's Your Name?", fg="red").pack()

def destroy():
root.destroy()

def button2():
    name = str(input1.get())
    print(name)

n = Button(root, text="Enter", command = button2).pack(side=LEFT)

input1 = Entry(root).pack(side=LEFT)

q = Button(root, text="Quit", command = destroy).pack(side=LEFT)

input1.focus_set()

def color():
    root["bg"] = input1.get()

c = Button(root, text="Change Color", command = color).pack()

root.mainloop()

任何帮助都会很棒。我知道这是我编写的代码,而不是其他任何东西。如果有帮助,这是它抛出的错误:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python33\lib\tkinter\__init__.py", line 1442, in __call__
    return self.func(*args)
  File "C:/Users/Kie/Documents/Computing/tkinter test.py", line 12, in button2
    name = str(input1.get())
AttributeError: 'NoneType' object has no attribute 'get'
4

0 回答 0