tkinter button命令参数显示错误:未知选项" -command"

时间:2016-04-02 15:22:48

标签: python python-3.x tkinter

我的这段代码显示错误:_tkinter.TclError:unknown option" -command"。我是新手,所以我可能犯了一个愚蠢的错误。请帮忙!

import tkinter
bod = tkinter.Tk()
button = tkinter.Button(bod, text="Hello (Click here)")
def hello():
    button = tkinter.Button(bod, text="Hello World!")
button.place(x=10, y=100, height="100", width="100", command=hello)
bod.mainloop()

1 个答案:

答案 0 :(得分:0)

你应该这样做:

from tkinter import *
def hello():
    button.config(text="Hello, World!")
bod = Tk()
button = Button(bod, text="Hello (Click here)", command=hello, height="100", width="100")  
button.pack()
bod.mainloop()

这会对您有所帮助:http://effbot.org/tkinterbook/button.htm#Tkinter.Button.config-method