为什么Frame不会出现在Tkinter中?(Why does the Frame not appear in Tkinter?)

系统教程 行业动态 更新时间:2024-06-14 17:02:18
为什么Frame不会出现在Tkinter中?(Why does the Frame not appear in Tkinter?)

我正在尝试构建一个基于你输入的音符播放音乐的程序。一切都在游泳,直到我试图添加不同的应用程序屏幕。 我有两个框架, songSelect和songSelect 。 我lift()那个我想要展示的那个。 唯一的问题是,什么都不会出现。

这是我的代码:

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

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

最满意答案

因为您使用place ,所以框架不会调整大小以适合其内容。 因此,您的框架只有一个像素高和宽。

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

更多推荐

本文发布于:2023-04-21 18:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/93c193e9ab95bb74af87584887201fdc.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:出现在   Frame   Tkinter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!