Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:检查现有名称,但函数未被触发_Python_Tkinter - Fatal编程技术网

Python:检查现有名称,但函数未被触发

Python:检查现有名称,但函数未被触发,python,tkinter,Python,Tkinter,大家好,我不知道为什么没有触发nameCheck功能。 我在设计上没有花太多精力,所以看起来很糟糕。 我用过特金特 标题框中的开始按钮应该触发nameCheck函数,该函数根据pName(列表)检查playerName(在标题框条目中) 我是否必须在函数外部创建一个单独的变量来存储playerName 顺便说一下,我对编码非常陌生,刚刚了解了def是什么。因此,请详细解释您的代码,谢谢(^-^)。按钮命令扩展位于不同的行上 import tkinter as tk root = tk.Tk(

大家好,我不知道为什么没有触发nameCheck功能。 我在设计上没有花太多精力,所以看起来很糟糕。 我用过特金特

标题框中的开始按钮应该触发nameCheck函数,该函数根据pName(列表)检查playerName(在标题框条目中)

我是否必须在函数外部创建一个单独的变量来存储playerName


顺便说一下,我对编码非常陌生,刚刚了解了def是什么。因此,请详细解释您的代码,谢谢(^-^)。

按钮命令扩展位于不同的行上

import tkinter as tk


root = tk.Tk()

Canvas = tk.Canvas(root, height = 700, width = 1300, bg = "black")
Canvas.pack()
w = 0.8
h = 0.8
x=0.1
y=0.1
pw = 0.3
ph = 0.3
px = 0.35
py = 0.35
pName = ["Jack","Thomas"]
pScore = [0,0]
pList = [0,1]

def ncYes():
        menuPage()
        pName.append(playerName)
        pScore.append(0)
        pList.append(0)
def ncNo():
        notice("Please re enter a new name.")
        titlePage()

def popup(question,yes,no):
    popupFrame = tk.Frame(root, bg = "white")
    popupFrame.place(relwidth = pw, relheight = ph, relx = px, rely = py)
    question = tk.Label(popupFrame, text = question, fg = "black", bg = "gray", font = "Arial 20 bold italic")
    title.pack()
    yes = tk.Button(popupFrame, text = "Yes", fg = "black", bg = "gray", font = "Arial 15 bold",command=yes)
    yes.pack()
    no = tk.Button(popupFrame, text = "No", fg = "black", bg = "gray", font = "Arial 15 bold",command=no)
    no.pack()

def notice(notice):
    noticeFrame = tk.Frame(root, bg = "white")
    noticeFrame.place(relwidth = pw, relheight = ph, relx = px, rely = py)
    notice = tk.Label(noticeFrame, text = notice, fg = "black", bg = "gray", font = "Arial 20 bold italic")
    title.pack()
    okay = tk.Button(noticeFrame, text = "Okay", fg = "black", bg = "gray", font = "Arial 15 bold",command=noticeFrame.destroy)
    okay.pack()

def nameCheck():
    for i in range(len(pName)) :
        if playerName == pName[i]:
            popup("Name already exist, is this your name?",ncYes,ncNo)
        else:
            if i == range(len(pName)):
                popup("Do you wanna create a new name?",ncYes,ncNo)


def menuPage():
    menuFrame = tk.Frame(root, bg = "white")
    menuFrame.place(relwidth = w, relheight = h, relx = x, rely = y)
    title = tk.Label(menuFrame, text = "Typing practice", fg = "black", bg = "gray", font = "Arial 30 bold italic")
    title.pack()
    titlebtn = tk.Button(menuFrame, text = "back", fg = "black", bg = "gray", font = "Arial 30 bold",command=titlePage)
    titlebtn.pack()

def titlePage():
    titleFrame = tk.Frame(root, bg = "white")
    titleFrame.place(relwidth = w, relheight = h, relx = x, rely = y)
    title = tk.Label(titleFrame, text = "Typing practice", fg = "black", bg = "gray", font = "Arial 50 bold italic")
    title.pack()
    playerName = tk.Entry(titleFrame, text = "Your name", fg = "black", bg = "gray", font = "Arial 30 italic")
    playerName.pack()
    start = tk.Button(titleFrame, text = "Start", fg = "black", bg = "gray", font = "Arial 30 bold",command=menuPage)
    start.pack()

titleFrame = tk.Frame(root, bg = "white")
titleFrame.place(relwidth = w, relheight = h, relx = x, rely = y)
title = tk.Label(titleFrame, text = "Typing practice", fg = "black", bg = "gray", font = "Arial 50 bold italic")
title.pack()
playerName = tk.Entry(titleFrame, text = "Your name", fg = "black", bg = "gray", font = "Arial 30 italic")
playerName.pack()
start = tk.Button(titleFrame, text = "Start", fg = "black", bg = "gray", font = "Arial 30 bold",command=nameCheck)
start.pack()


 






warmUp = tk.Button(root, text = "Warmup", padx = 10, pady = 5, fg = "white", bg="black")
warmUp.pack()
quit = tk.Button(root, text = "Quit", padx = 10, pady = 5, fg = "white", bg="black", command = root.destroy)
quit.pack()

root.mainloop()

请将代码量减少到所需的最小值。有很多代码与问题无关。请参阅。
playerName
是一个小部件。它不是用户输入到小部件中的文本(将通过
playerName.get()检索)
,因此将永远不会等于列表中的任何名称。您如何知道该函数未被触发?您是否尝试在函数开头向控制台打印一些内容以查看是否执行该函数?您知道,当python将其编译为python字节码时,它将是相同的。大多数新行/空白s(不是缩进的一部分)被删除。将其放在另一行上没有任何作用
btnRead=tk.Button(root, height=1, width=10, text="Insert GUI", 
                command=getTextInput)