for 루프를 사용하여 단추 목록을 만들고 단추를 클릭하면 "사용할 수 없음"이라는 텍스트가 업데이트됩니다. 아래 내 코드는 지정된 버튼이 아닌 최신 버튼 만 업데이트합니다.
from tkinter import *
root = Tk()
list = ["button 1 available", "button 2 available", "button 3 available"]
def update(item):
btn["text"] = item.replace("available", "unavailable")
for item in list:
btn = Button(root, text=item, command=lambda : update(item))
btn.pack()
root.mainloop()
이것은 당신의 필요에 맞을 것입니다.
from tkinter import *
root = Tk()
buttonTextList = ["button 1 available", "button 2 available", "button 3 available"]
def update(item, btn):
btn["text"] = item.replace("available", "unavailable")
# Function to create button
def createButton(item):
btn = Button(root, text=item, command=lambda: update(item, btn))
btn.pack()
# Updated for loop
for item in buttonTextList:
createButton(item)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다