Python 未定义名称主屏幕
我是一个初学者,最近开始使用tkinter库。我有一个问题:我在一个使用global的函数中声明了MainScreen,但它说MainScreen的名称没有定义。请帮忙Python 未定义名称主屏幕,python,tkinter,mainscreen,Python,Tkinter,Mainscreen,我是一个初学者,最近开始使用tkinter库。我有一个问题:我在一个使用global的函数中声明了MainScreen,但它说MainScreen的名称没有定义。请帮忙 import tkinter from tkinter import * start_screen = tkinter.Tk() start_screen.title("Start screen") start_screen.attributes(
import tkinter
from tkinter import *
start_screen = tkinter.Tk()
start_screen.title("Start screen")
start_screen.attributes('-fullscreen', True)
def stop_start():
start_screen.destroy()
global MainScreen
MainScreen = tkinter.Tk()
MainScreen.title("Main Screen")
MainScreen.attributes('-fullscreen', True)
Label(start_screen, text=' ', height=20).pack(side='top')
strt_btn = Button(start_screen, text="START", command=stop_start).pack(side='top')
def x_btn_root():
MainScreen.destroy()
LabelFrame(MainScreen, width=1280, bg='gray').grid(row=0, column=0)
Button(LabelFrame, text="X", highlightcolor='red', command=x_btn_root).pack(side='left')
start_screen.mainloop()
您试图在执行
stop\u start()
之前引用它,因此它不存在。无论如何,您不应该多次调用tkinter.Tk()
。start\u screen.mainloop()
之前的最后两行是否在stop\u start()
函数中?您试图在执行stop\u start()
之前引用它,因此它不存在。无论如何,您不应该多次调用tkinter.Tk()
。在start\u screen.mainloop()
之前的最后两行是否应该在stop\u start()
函数中?