2017-05-31 38 views
0

我学习Python的Tkinter的基本面,并不能得到所谓我的方法“提交()”,力主对我的条目1变量的字符串值。 我曾尝试获得()方法条目1,但控制台说的get属性不为条目1存在。的Python的Tkinter - 吵了输入字符串输入()

from tkinter import * 

Window = Tk() 

def Submit(): 
    Answer = Entry1.text 
    if Answer == "byte": 
    print("correct") 

Label(Window, text="What do you call 8 bits?").grid(row=0) 
Entry1 = Entry(Window, text="").grid(row=1) 
Button(Window, text="SUBMIT", command=Submit).grid(row=2) 

Window.mainloop() 

回答

1

我想通了。谢谢,不过。

from tkinter import * 
Window = Tk() 

def Quiz(): 
    if Answer1.get() == "8" : 
     print("correct") 

Question1 = Label(Window, text="How many bits are in a  Byte?").grid(row=0) 
Answer1 = StringVar() 
Entry1 = Entry(Window, textvariable=Answer1).grid(row=1) 
Button1 = Button(Window, text="ANSWER", command=Quiz).grid(row=2) 

Window.mainloop()