简体   繁体   中英

Why does the Frame not appear in Tkinter?

I am trying to build a program that plays music based on notes that you put in. Everything was going swimmingly untill I tried to add different screens of the application. I have two frames, songSelect and mainMenu . I lift() the one that I want to display at that time. The only problem is, that nothing will appear.

Here is my code:

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()

Because you use place , the frames don't resize to fit their contents. Therefore your frame is only one pixel tall and wide.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM