窗口“root2”中的标签“totalresults”未显示。我想更新的文字标签,每次按钮是在第一个窗口按下,并计算这些按钮按下的数量
#create the window
root = Tk()
root2 = Tk()
#probability calculations
totalrolls = tk.StringVar()
amountofrolls = 0
#update numbers in gui
def add_num():
global amountofrolls
amountofrolls += 1
totalrolls.set("Amount of rolls made in total: " +str(amountofrolls))
#button functions
def button_press():
add_num()
#string variable
totalrolls.set("Amount of rolls made in total: " + str(amountofrolls))
#modify second window
todennäköisyys = Label(root2, text="The quantity of results:")
totalresults = Label (root2, textvariable=totalrolls)
todennäköisyys.pack()
totalresults.pack()
#kick off the event loop
root.mainloop()
root2.mainloop()
我没有得到任何错误或任何东西的第二个窗口只是显示标签
不应启动多个
Tk()
实例。改用Toplevel()
。参见示例:相关问题 更多 >
编程相关推荐