我希望看不见的标签显示为绿色应该是" @"符号,但它不会这样做而只是什么也不做。我希望这会继续下一个功能,我可以自己做。如果" @"我可以改变它,以便标签出现。符号不在字符串中,但是当@符号实际上在字符串中时它不接受它。
from tkinter import *
class Traveller:
def __init__(self, parent):
self.E_email = "sd"
self.go = Frame(parent, width=500, height=450, bg="snow", pady=30, padx=10)
self.go.grid(row=1, column=0)
self.go.grid_propagate(0) # to reserve space required for frame
email = Label(self.go, text="Email:", bg="snow")
email.grid(row=3, column=0, sticky=E)
self.E_email = Entry(self.go, width=40)
self.E_email.grid(row=3, column=1, sticky=W, pady=4)
menuButton = Button(self.go, text="Continue", command=self.dataCheck)
menuButton.grid(row=8, column=1, pady=8)
self.meme = Label(self.go, text = "", bg = "snow")
self.meme.grid(row=9, column=0, columnspan = 3)
def dataCheck(self):
self.E_email = str(self.E_email)
if "@" in self.E_email:
self.meme.configure(text="memem", bg = "olive drab")
# main routine
if __name__ == "__main__":
root = Tk()
root.title("Traveller Details")
play = Traveller(root)
root.geometry("500x450+0+0")
root.mainloop()
答案 0 :(得分:1)
您必须使用self.E_mail.get()
来获取条目小部件内的文本。
if "@" in self.E_mail.get():
...