簡體   English   中英

Python Tkinter-如何使用entry.get()從條目放置輸入

[英]Python Tkinter - How to place the input from an entry using entry.get()

我有一個名為“用戶名”的條目。

username = Entry()
username.place(x = 10, y = 50)

和一個提交按鈕

submit = Button(text="Submit", command=getInfo)
submit.place(x = 150, y = 48)

它調用一個getInfo函數

def getInfo():
 user = username.get()

我想將用戶放置為標簽。 我可以很好地打印它,文本顯示在控制台中。 當我嘗試放置時,出現錯誤。

File "tk.py", line 8, in getInfo
user.place(x = 150, y = 90)
AttributeError: 'str' object has no attribute 'place'

就像錯誤消息說的那樣, user是字符串,而不是小部件。 因此,它沒有諸如usernamesubmit這樣的place方法。 您想要將其粘貼到標簽中,然后放置標簽。

如錯誤消息所述: user是一個字符串。 您知道這是一個字符串,因為您是使用get()Entry小部件中get() ,該函數返回一個字符串。 您需要制作一個新的小部件來容納此字符串,然后將其放置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM