亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Python:tkinter.TclError:無法調用“標簽”命令:應用程序已被破壞

Python:tkinter.TclError:無法調用“標簽”命令:應用程序已被破壞

炎炎設計 2023-12-12 14:59:22
當我退出 tk 窗口時,我收到這個長庫錯誤,而且我不知道如何修復它。GUI 本身和錯誤消息位于代碼下方。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貢獻1810條經驗 獲得超4個贊

基本上想象一下,您的代碼執行到mainloop()并在那里暫停,直到您跳出循環,即退出應用程序。然后執行后的代碼mainloop(),即為true 的語句,因此運行調用激活標簽的if函數。golf_record()GUI_print()

如何解決這個問題?我不確定您在這里嘗試使用此代碼做什么,但如果您可以將其移至語句root.mainloop()末尾if,它將在代碼最初執行時執行該函數。如果您還有更多疑問,請告訴我。或者更好的方法是擺脫golf_records()內部的函數調用,if因為無論如何都有一個調用該函數的按鈕。


查看完整回答
反對 回復 2023-12-12
  • 1 回答
  • 0 關注
  • 240 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號