有没有办法停止tkinter条目循环?

时间:2019-03-31 00:20:55

标签: python loops tkinter conditional-statements

我创建了一个while循环,该循环应检查条目中是否包含2、3或4。当我尝试不带tkinter输入框的循环时,它会根据需要循环并停止。当我将其与tkinter条目合并时,它会无限循环。我是python tkinter的新手,正在尝试建立一个工作系统。

已经尝试了没有tkinter条目的循环。现在已经研究了几个小时。

from tkinter import *
def sentence():
    global text 
    text = musicEntry.get()
    musicEntry.delete(0,END)
    countIt = 0
    while countIt == 0:             
        for line in text:
            if line in "2" or line in "3" or line in "4":
                countIt = 1
                messagebox.showinfo("All is well. Please press the SUBMIT button to continue")
                break
        else:
            print("This doesn't work")

def checkPass():
    global musicEntry
    enterText = Tk()
    enterText.title ("Welcome to music chooser")
    Label(enterText, text = "Please enter the music text", bg="black", fg="white", font="none 12 bold") .grid(row=7, column = 0, sticky=W) 

    #Create a text entry box for music level
    musicEntry = Entry(enterText, width=75, bg="white")
    musicEntry.grid(row=8, column=0, sticky=W)
    validateButton = Button(enterText, text="Validate", width=6, command=sentence) .grid(row=9, column=0, sticky=W)
checkPass()

我希望在执行else时,验证能够捕获丢失的2、3或4,这样我就可以为用户提供一个消息框。

0 个答案:

没有答案