Python 为什么框架不出现在Tkinter中?

Python 为什么框架不出现在Tkinter中?,python,tkinter,Python,Tkinter,我正在尝试建立一个程序,根据你输入的音符播放音乐。一切都进行得很顺利,直到我尝试添加应用程序的不同屏幕。我有两个框架,歌曲选择和主菜单。我举起了我当时想展示的那个。唯一的问题是,什么也不会出现 这是我的密码: root = Tk() root.title("Music Creator") root.geometry("300x230") root.iconbitmap(default='favicon.ico') root.resizable(width=FALSE, height=FALSE)

我正在尝试建立一个程序,根据你输入的音符播放音乐。一切都进行得很顺利,直到我尝试添加应用程序的不同屏幕。我有两个框架,歌曲选择和主菜单。我举起了我当时想展示的那个。唯一的问题是,什么也不会出现

这是我的密码:

root = Tk()
root.title("Music Creator")
root.geometry("300x230")
root.iconbitmap(default='favicon.ico')
root.resizable(width=FALSE, height=FALSE)

mainMenu = Frame(root)
songSelect = Frame(root)

def raiseFrame(frame):
    frame.lift()

mainMenu.lift()

programName = Label(mainMenu, text="Music Creator", font=("Helvetica",20))

noteLabel = Label(mainMenu, text="Notes to play:")
tempoLabel = Label(mainMenu, text="Interval to play the notes at: (In seconds)")

noteEntry = Entry(mainMenu)
tempoEntry = Entry(mainMenu)

playButton = Button(mainMenu, text="Play", command=lambda: playNotes(noteEntry.get(),tempoEntry.get()))
loadButton = Button(mainMenu, text="Load", command=lambda: raiseFrame(songSelect))

programName.place(relx=0.5,y=25,anchor=CENTER)
noteLabel.place(relx=0.5,y=60,anchor=CENTER)
noteEntry.place(relx=0.5,y=90,anchor=CENTER)
tempoLabel.place(relx=0.5,y=130,anchor=CENTER)
tempoEntry.place(relx=0.5,y=160,anchor=CENTER)
playButton.place(relx=0.5,y=200,anchor=CENTER)
loadButton.place(x=10,y=40)

root.mainloop()
mainMenu.mainloop()

由于使用“放置”,框架不会调整大小以适应其内容。因此,您的帧只有一个像素高和宽

@Legodog5678:我建议对框架内的小部件使用grid或pack。或者,为框架指定明确的宽度和高度。网格和包装几乎总是优于放置。我将设置框架的显式宽度和高度。我想使用网格,但我不知道如何使用网格来居中。你能解释一下吗?