tkinter GUIの新機能です。私は、printというボタンにコマンドを割り当てる例を以下で試していました。私が間違っているつもりです任意のアイデアは、私はエラーを取得:Tkinterボタンへのコマンドの割り当て
_tkinter.TclError: bad option "-command": must be -after, -anchor, -before, -expand, -fill, -in, -ipadx, -ipady, -padx, -pady, or -side
Tkinterのインポートから*
class App:
def __init__(self, master):
fm = Frame(master)
Button(fm, text='Print').pack(side=TOP, anchor=W, fill=X, expand=YES, command = self.hello_world)
Button(fm, text='Center').pack(side=TOP, anchor=W, fill=X, expand=YES)
Button(fm, text='Bottom').pack(side=TOP, anchor=W, fill=X, expand=YES)
Button(fm, text='Left').pack(side=LEFT)
#Button(fm, text='This is the Center button').pack(side=LEFT)
Button(fm, text='Right').pack(side=RIGHT)
fm.pack(fill=BOTH, expand=YES)
def hello_world(self):
print ("Hello World")
root = Tk()
root.resizable(width=False, height=False)
root.option_add('*font', ('verdana', 12, 'bold'))
root.title("Pack - Example 12")
display = App(root)
root.mainloop()
エラーはわかりやすいものですが、 'command'は[widgetのオプション](http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/button.html)です。 'Button'クラスの引数)であり、' pack'メソッドの引数ではありません。 – CommonSense
'ボタン(...、コマンド= ...)' – furas