新的窗口格式



我正在尝试在新窗口中添加一行文本,然后是文本框,然后在一行上添加一个按钮,然后在第 2 行和第 3 行上添加相同的按钮,但由于某种原因我无法使用 .grip。

因此,当我运行脚本时,我没有得到 3 个文本框,但确实得到了三行文本和三个按钮。

请耐心等待,因为我对所有这些:(都很陌生

def open_window():
window = Tk()
window.geometry('400x150+1000+500')
window.title('PSX CFD Config')
ip = StringVar()
Label(window, text="Enter IP Address", font=("Verdana", 13)).pack()#.grid(row=1, column=1)
Label(window, text="Enter IP Address", font=("Verdana", 13)).pack()#.grid(row=2, column=1)
Label(window, text="Enter IP Address", font=("Verdana", 13)).pack()#.grid(row=3, column=1)
Entry(window, textvariable=ip)#.grid(row=2, column=3)
Entry(window, textvariable=ip)#.grid(row=2, column=3)
Entry(window, textvariable=ip)#.grid(row=2, column=3)
Button(window, text="Set", font=("Verdana", 13), command=file_explorer).pack()#.grid(row=1, column=2)
Button(window, text="Set", font=("Verdana", 13), command=file_explorer).pack()#.grid(row=1, column=2)
Button(window, text="Set", font=("Verdana", 13), command=file_explorer).pack()#.grid(row=1, column=2)
window.mainloop()

调试终端中没有错误

似乎你只是弄乱了行和列:

以下内容根据需要显示 3 行:

window = Tk()
window.geometry('400x150+1000+500')
window.title('PSX CFD Config')
ip = StringVar()
Label(window, text="Enter IP Address", font=("Verdana", 13)).grid(row=1, column=1)
Label(window, text="Enter IP Address", font=("Verdana", 13)).grid(row=2, column=1)
Label(window, text="Enter IP Address", font=("Verdana", 13)).grid(row=3, column=1)
Entry(window, textvariable=ip).grid(row=1, column=2)
Entry(window, textvariable=ip).grid(row=2, column=2)
Entry(window, textvariable=ip).grid(row=3, column=2)
Button(window, text="Set", font=("Verdana", 13), command=file_explorer).grid(row=1, column=3)
Button(window, text="Set", font=("Verdana", 13), command=file_explorer).grid(row=2, column=3)
Button(window, text="Set", font=("Verdana", 13), command=file_explorer).grid(row=3, column=3)
window.mainloop()

注意:您可能需要创建 3 个不同的ip,除非您希望在任何地方都使用相同的文本?

最新更新