Python 如何打开子窗口?

Python 如何打开子窗口?,python,tkinter,Python,Tkinter,请帮助修复脚本 import tkinter def winMake(parent): win = tkinter.Frame(parent) win.config(relief = 'sunken', width = 340, height = 170, bg = 'red') win.pack(expand = 'yes', fill = 'both') msg = tkinter.Button(win, text='press me', command

请帮助修复脚本

import tkinter

def winMake(parent):
    win = tkinter.Frame(parent)
    win.config(relief = 'sunken', width = 340, height = 170, bg = 'red')
    win.pack(expand = 'yes', fill = 'both')

    msg = tkinter.Button(win, text='press me', command = addFormOpen)
    msg.pack()

def addFormOpen():
    addForm = tkinter.Toplevel(root)
    Label(addForm, text = 'ertert').pack()
    print('fff')

root = tkinter.Tk()
winMake(root)
root.mainloop()
点击按钮后,“按我”将打开一个子窗口。但控制台会显示一条错误消息:

Exception in Tkinter callback Traceback (most recent call last):  
  File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__
    return self.func(*args)   File "C:\Python33\projects\DVD_LIS\p3_dvd_list_shelve_3d_class_edit_menubar\q.py", line 13, in addFormOpen
    Label(addForm, text = 'ertert').pack() 
NameError: global name 'Label' is not defined

您导入了包含类
标签的名称
tkinter
。也就是说,为了访问它,您需要将
tkinter.
放在它前面(就像您对
按钮
等所做的那样):

否则,Python将不知道在哪里定义了
标签

tkinter.Label(addForm, text = 'ertert').pack()