-3

这是我的代码:

import sys
from tkinter import *


def next_screen(names):
    for widget in names:
        widget.place_forget()   

def forget_page1():
    widgets = [mLabel1, button]
    next_screen(widgets)

mGui = Tk ()

mGui.geometry("600x600+545+170")
mGui.title("MyMathDictionary")
mLabel1 = Label (text = "Welcome to MyMathDictionary. Press Next to continue.",
                 fg = "blue",bg = "white")
mLabel1.place (x= 150,y = 200)

button = Button (text = "Next", command = forget_page1 ())
button.place(x = 275,y = 230)

mGui.mainloop()

它告诉我:

Traceback (most recent call last):   File
"C:\Python33\Projects\MyMathDictionary.py", line 24, in <module>
    button = Button (text = "Next", command = forget_page1 (mLabel,button)) NameError: name 'button' is not defined

这个错误信息是什么意思?

4

1 回答 1

1

更改这行代码:

button = Button (text = "Next", command = forget_page1 ())

对此:

button = Button (text = "Next", command = forget_page1)

您的问题是您forget_page1在加载窗口之前调用。

此外,正如评论已经说过的那样,您的错误与您的代码不同。但是,为了以防万一,我也会很快过一遍。如果要将参数发送到按钮的命令函数,则需要使用lambda

button = Button(command = lambda: func(arg1, arg2))
于 2013-08-09T13:35:17.390 回答