イベントで後で有効になる最初は[無効]ボタンが必要です。私はボタンに状態の変更を得ることができないということを除いて、かなり大きなアプリケーションを使用しています。コードを完全に修復する必要があると私に言わないでください。これは、私が使用している顕著な構造を残しているすべてのコードのうちの1つです。 ReadPortは実際には 'after'から呼び出されますが、ここでボタンプレスでシミュレートされます。キャンバスボタンの状態を通常に設定する方法(Python 3)
私はこの件に関するすべてのヘルプを読み、回答を試みました。 Pythonステートメントとそれぞれのエラーは、ボタンの状態を変更しようとすると、この完全なアプリケーションで失敗します。これを修正する方法を教えてください。
#!/usr/bin/python 3
from tkinter import *
def ReadPort():
global VSM_Button
# AttributeError: 'NoneType' object has no attribute 'config'
## VSM_Button.config(state="normal")
# AttributeError: 'NoneType' object has no attribute 'configure'
## VSM_Button.configure(state="normal")
# TypeError: 'NoneType' object does not support item assignment
## VSM_Button['state'] = 'normal'
# AttributeError: 'NoneType' object has no attribute 'configure'
## VSM_Button.configure(state=NORMAL)
# ??? How do I set the button state to 'normal' ?
pass
class Application:
def __init__(self, master):
#global VSM_Button # seems unnecessary. Same errors in or out.
frame = Frame(master)
frame.pack()
Button(frame, text='Press Me', width = 10, command=ReadPort).pack()
VSM_Button = Button(frame, text='Disabled', width = 10, state = DISABLED).pack()
pass # end def __init__
pass # end class Application
root = Tk()
root.wm_title('Button')
app = Application(master=root)
root.mainloop()
"NoneType 'オブジェクトには属性がありません"というエラーに関するこのサイトの質問と回答は、おそらく何百もあります。 –