【问题标题】:Is there a way to change the text of the button when the button clicked [duplicate]有没有办法在单击按钮时更改按钮的文本[重复]
【发布时间】:2020-07-10 08:11:54
【问题描述】:

有没有办法在单击按钮时更改按钮的文本?

编辑:nvm 我解决了它的类似文本

【问题讨论】:

标签: python button tkinter


【解决方案1】:

这是否有助于您解决问题。使用 .config() 可以更新 tkinter 中的按钮

from tkinter import Button,Tk


root = Tk()


def click():
    b.config(text='You jus clicked me!')


b = Button(root, text='Click me', command=click)
b.pack()

root.mainloop()

【讨论】:

  • 但我的 Python IDE 说:NameError: name 'b' is not defined (in def)
  • 你命名你的按钮变量b了吗?或者别的什么
  • 我没有将按钮命名为 b,但我的变量是“menu”,所以我使用了这个:menu.config(text="You jus clicked me!")
  • 在你的代码中的某处,这么提到 b,你 pack 它使用 b 吗?你可以在这里发布你的按钮和功能代码
  • def click(): menu.config(text='你刚刚点击了我!') menu = Button(root, text='点击我', command=click) menu.pack()
猜你喜欢
  • 1970-01-01
  • 2022-06-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多