我如何在我的 def new_window() 函数中定位我的标签,上面写着“问题一”。当你运行它时,标签被定位在底部,我希望它被应用在顶部。from tkinter import *from tkinter import ttk#User Interface Coderoot = Tk() # Creates the windowroot.title("Quiz Game")def new_window(): newWindow = Toplevel(root) display = Label(newWindow, width=150, height=40) message = Label(newWindow, text="Question One", font = ("Arial", "24")) display.pack() message.pack()display2 = Label(root, width=100, height=30, bg='green')button1 = Button(root, text ="Continue", command=new_window, width=16, bg="red")message_label1 = Label(text="A Quiz Game", font = ("Arial", "24"), padx=40, pady=20)message_label2 = Label(root, text="Click 'Continue' to begin.", wraplength=250)display2.pack()button1.pack()message_label1.pack()message_label2.pack()root.mainloop() # Runs the main window loop
1 回答
慕工程0101907
TA贡献1887条经验 获得超5个赞
您按错误的顺序打包。不要打包显示before您的message. 因此,只需交换订单即可解决问题。
这是代码。def new_window():用这个替换你的
def new_window():
newWindow = Toplevel()
message = Label(newWindow, text="Question One", font = ("Arial", "24"))
display = Label(newWindow, width=150, height=40)
message.pack()
display.pack()
pack方法只是盲目地将小部件打包到窗口中。pack如果有空间,下一个将在它下面完成。所以在打包小部件时要注意顺序:)
添加回答
举报
0/150
提交
取消