2016-12-12 5 views
0

私はPython Tkinterでは、特定の行の背景色を変更しますか?

master.configure(background = 'SteelBlue1') 
titlelabel = Tkinter.Label(master, text="my Title", fg = "blue4", bg = "gray80").grid(row=0, column = 1) 

行0グレーを作るための簡単な方法だけではなくラベルの周りの領域が存在し、ウィンドウ全体のこのによる特定のラベルの背景色を変更することができましたか?おかげ

+1

私は100%確実ではないので(答えは答えられません)、フレーム内にラベルをラップして(行全体を埋めるように)設定し、色を変更する必要があります。それ。 – scotty3785

答えて

1

は、この行のタイトルだけがある場合、あなたはすべての列の上にタイトルスパンようcolumspanを使用することができますし、水平にラベルを展開します。

import Tkinter 

master = Tkinter.Tk() 

master.configure(background='SteelBlue1') 
master.columnconfigure(0, weight=1) # make the column 1 expand when the window is resized 
nb_of_columns = 2 # to be replaced by the relevant number 
titlelabel = Tkinter.Label(master, text="my Title", fg="blue4", bg ="gray80") 
titlelabel.grid(row=0, column=0, sticky='ew', columnspan=nb_of_columns) # sticky='ew' expands the label horizontally 

master.geometry('200x200') 
master.mainloop() 

をそれ以外の場合は、解決策はscotty3785アドバイスに従うことで、

import Tkinter 

master = Tkinter.Tk() 

master.configure(background='SteelBlue1') 
master.columnconfigure(1, weight=1) 

nb_of_columns = 2 # to be replaced by the relevant number 
titleframe = Tkinter.Frame(master, bg ="gray80") 
titleframe.grid(row=0, column=0, columnspan=nb_of_columns, sticky='ew') 
titlelabel = Tkinter.Label(titleframe, text="my Title", fg="blue4", bg ="gray80") 
titlelabel.grid(row=0, column=1) 
# other widgets on the same row: 
Tkinter.Button(titleframe, text='Ok').grid(row=0, column=2) 

master.geometry('200x200') 
master.mainloop() 
関連する問題