我嘗試了很多方法來解決這個問題,但是訊息“<bound method StringVar.get of <tkinter.StringVar object at 0x00000000024FB8E0>>”一直顯示,.get() 方法由于某種原因也不起作用,這里是編碼:
root.title("Testing this thing :D")
v = tk.StringVar()
label1 = tk.Label(root,text="Write your name").pack()
entrybox = tk.Entry(root,font= ("Arial 12"),textvariable=v).pack(expand=True)
def showmsg():
label = tk.Label(root, text = f"Hello {v.get}",font=("Arial 12")).pack()
button = tk.Button(root,font=("Arial 12"), command= showmsg(),text="Done").pack(fill= X)
root.mainloop()
uj5u.com熱心網友回復:
您的代碼中有兩個問題。
在 Button 中,你給
command=showmsg()Here 你呼叫這個函式這應該是command=showmsg在
showmsg您撰寫的函式中,var.get這應該是var.get().
import tkinter as tk
root = tk.Tk()
root.title("Testing this thing :D")
v = tk.StringVar()
label1 = tk.Label(root,text="Write your name").pack()
entrybox = tk.Entry(root,font= ("Arial 12"),textvariable=v).pack(expand=True)
def showmsg():
label = tk.Label(root, text = f"Hello {v.get()}",font=("Arial 12")).pack()
button = tk.Button(root,font=("Arial 12"), command= showmsg,text="Done").pack(fill= tk.X)
root.mainloop()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/486339.html
