是否有人知道以下方面的替代方案: 根=tk()
当我运行我的程序,多个窗口同时运行,只是想知道是否有一个替代方案,使它们不会同时打开。当按下初始窗口上的按钮时,应启动程序运行后立即打开的第二个窗口。我还尝试使用: 根=顶层() 但结果是一样的。 有什么想法吗?谢谢
def Search_Inventory():
#---First Window----
root = Toplevel()
root.title("Warehouse Inventory Control System")
root.configure(bg = "black")
#----Title displayed under the company logo on the first window----
Title_Screen = Label(root,
text="Warehouse Inventory Control System",
fg="grey",
bg="black",
font="Helevetica 25 bold",
pady = "50",
padx = "50",
).grid(row=3, column=4)
#----Interactive Input Boxes for the User----
#----Label to Notify what is needed in the entry box----
PN_Info_Label = Label(root,
text = "Part Number:",
fg="white",
bg="black",
font="Helevetica 15 bold",
padx = 50,
).grid(row=14, column=3, rowspan = 2)
#----Input Box for Part Number
PN_Display = StringVar()
Input_PartNumber = Entry(root,
textvariable=PN_Display,
fg = "blue",
font = "Helevtica 25 bold",
).grid(row=14, column=4)
#----A button that will proceed to the next part of the program----
Search_Button = Button(root,
text = "Search Inventory",
fg = "Blue",
bg = "Grey",
bd = 2,
font="Helevetica 15 bold",
command=lambda:Search_Prod(PN_Display.get()),
height = 1,
width = 15,
).grid(row=16, column=4,pady = 25,padx = 25,)
#----Information regarding how to enter the part number---
Info = Label(root,
text="Please Use Capitals to Enter Part Number",
fg= "red",
bg = "black",
font = "helevetica 12 bold",
).grid(row = 15, column = 4)
#----Adding the company logo to the first window----
photo = PhotoImage(file="image.gif")
photoLabel = Label(image=photo)
photoLabel.image = photo
photoLabel.grid(row=1, column=4, pady = 10)
#----Linking the Help Document----
Help_Button = Button(root,
text = "Help",
command=Help_PDF,
fg = "Red",
bg = "Black",
height = "1",
bd = "2",
font = "Helevetica 20 bold",
width = "4",
).grid(row=0, column=5, pady= 10,padx = 50, sticky = E)
#----Saying who the program was made by----
Credits = Label(root,
text = "Created By: Me",
fg = "White",
bg = "Black",
font = "Helevetica 10 underline",
).grid(row = 19, column = 5)
#To Make Sure that the window doesn't close
root.mainloop()
这是一个子程序,它本打算稍后运行,但却直接运行。在
^{pr2}$这是最初要弹出的内容,但与另一个完全混淆。在
command=
需要函数名-callback-表示没有()
但你有
()
在里面这就是为什么这是在开始时执行的,而不是当你点击按钮时
顺便说一句:
tkinter
只需要一个mainloop()
-如果你使用两个mainloop()
,那么它就不能正常工作了。在编辑:图像的问题是因为您没有在第二个窗口中为
^{pr2}$Label
设置父项所以它默认使用主窗口
你需要
编辑:最小工作代码
别无选择。tkinter应用程序绝对必须有一个根窗口。如果您没有显式地创建一个(您应该这样做),那么在您第一次创建任何其他小部件时,将为您创建一个。在
这样做的原因是你让它马上打开。看看这个代码:
上述代码与此相同:
^{pr2}$请注意,命令中缺少
()
。command
属性需要对函数的引用。在相关问题 更多 >
编程相关推荐