炎炎設(shè)計(jì)
2023-12-12 14:59:22
當(dāng)我退出 tk 窗口時(shí),我收到這個(gè)長(zhǎng)庫(kù)錯(cuò)誤,而且我不知道如何修復(fù)它。GUI 本身和錯(cuò)誤消息位于代碼下方。def golf_records()->None: """ This function prints the information of golfer names and the score they have """ with open("golf.txt", "r") as myfile: myfile_content = myfile.read() GUI_print(myfile_content)def GUI_print(data)->None: """ The function takes in a string found in golf.txt file and prints it out through tkinter GUI """ my_label = Label(root,text = str(data),font=("ariel",15)).place(x=250,y=120) root = Tk()root.geometry("600x600")#Lablesheader = Label(root,text = "Current Golf Records",font=("ariel",15,"bold")).place(x=150,y=20)header = Label(root,text = "-----------------------------",font=("ariel",15)).place(x=150,y=50)header = Label(root,text = "Press enter to list players data: ",font=("ariel",15)).place(x=150,y=80)#Buttonsenter = Button(root, text="Enter", activebackground = "green", command=golf_records).place(x=440,y=80)root.mainloop()if __name__ == "__main__": golf_records()
1 回答

慕萊塢森
TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊
基本上想象一下,您的代碼執(zhí)行到mainloop()
并在那里暫停,直到您跳出循環(huán),即退出應(yīng)用程序。然后執(zhí)行后的代碼mainloop()
,即為true 的語(yǔ)句,因此運(yùn)行調(diào)用激活標(biāo)簽的if
函數(shù)。golf_record()
GUI_print()
如何解決這個(gè)問(wèn)題?我不確定您在這里嘗試使用此代碼做什么,但如果您可以將其移至語(yǔ)句root.mainloop()
末尾if
,它將在代碼最初執(zhí)行時(shí)執(zhí)行該函數(shù)。如果您還有更多疑問(wèn),請(qǐng)告訴我?;蛘吒玫姆椒ㄊ菙[脫golf_records()
內(nèi)部的函數(shù)調(diào)用,if
因?yàn)闊o(wú)論如何都有一個(gè)調(diào)用該函數(shù)的按鈕。
添加回答
舉報(bào)
0/150
提交
取消