2017-03-14 2 views
1

私は、複数のメニューとボタンを使用し、メニューを素早く作成するプログラムを作成しています(私はTkinterに堪能ではありません)。しかし、ボタンごとに非常に長い.configure文が出力されています。つまり、私のプロジェクトは現在1400行以上のコードを集めています。これらの.configureコマンドをすべて1つにする方法はありますか?私は参照のために私のコードのサンプルを以下に含めました。TKinterの.configureを1つのコマンドに集約するにはどうすればいいですか?

self.Button7 = Button(top) 
self.Button7.place(relx=0.04, rely=0.76, height=24, width=257) 
self.Button7.configure(activebackground="#d9d9d9") 
self.Button7.configure(activeforeground="#000000") 
self.Button7.configure(background="#d9d9d9") 
self.Button7.configure(command=root.destroy) 
self.Button7.configure(disabledforeground="#a3a3a3") 
self.Button7.configure(foreground="#000000") 
self.Button7.configure(highlightbackground="#d9d9d9") 
self.Button7.configure(highlightcolor="black") 
self.Button7.configure(pady="0") 
self.Button7.configure(text='''Go back''') 
+0

「ページ」とは何ですか? –

答えて

1

設定のために渡す必要がある引数のdictionaryを作成し、次にargument unpacking magic**を使用することができます。

my_config = { 
    'foreground': "#000000", 
    'background': "#d9d9d9", 
    # ... 
} 
self.Button7.configure(**my_config) 
1

あなたは、単一のコマンドでそれらのすべてを置くことができます。

self.Button7.configure(foreground="#000000", highlightbackground="#d9d9d9", highlightcolor="black", etc) 

しかし、なぜあなたがしたいですか?あなたのやり方にするのはずっとやっかいです。

+0

あなたは '' .configure() ''を全く使う必要はありません。同じキーワードは '' Button() ''コンストラクタで直接動作します。 – jasonharper

関連する問題