私の質問は、tkinterを使ってPythonでGUIプログラミングをすることです。私はこれがPython 3xだと信じています。ボタンプレスからtkinterのラベルを更新する
私の質問:GUIを実行するプログラムを実行しているうちに、ボタンでラベルを更新できますか?具体的には、ボタンを押した後に表示されるラベルを変更する方法はありますか?私はこの前にスタックオーバーフローを参照してStringVar()メソッドを採用しましたが、実際にはGUIからテキストを完全に省略して自分の問題を修正するようには見えません!ここで
は、任意の助けをいただければ幸いです
from tkinter import *
root = Tk()
root.title('Copy Text GUI Program')
copiedtext = StringVar()
copiedtext.set("Text is displayed here")
def copytext():
copiedtext.set(textentered.get())
# Write 'Enter Text Here'
entertextLabel = Label(root, text="Enter Text Here")
entertextLabel.grid(row=0, column=0)
# For the user to write text into the gui
textentered = Entry(root)
textentered.grid(row=0, column=1)
# The Copy Text Button
copytextButton = Button(root, text="Copy Text")
copytextButton.grid(row=1, columnspan=2)
# Display the copied text
displaytextLabel = Label(root, textvariable=copiedtext)
displaytextLabel.grid(row=2,columnspan=2)
copytextButton.configure(command=copytext())
root.mainloop()
以下のコードです!あなたがしなければならない何
をまた、私の改正として、質問、私はdisplaytextLabelのtextvariableの代わりにテキストを書いたとき、それはPY-4060(私はこれがメモリではないと仮定していると思います)を出力するので、問題ではないことが分かります。 – Afr0