2012-06-04 170 views
3

我試圖創建一個黑色背景的根窗口與我的按鈕背景混合。Python/Tkinter根窗口背景配置

我有以下幾點:

class Application(Frame): 
    def __init__(self, parent): 
     Frame.__init__(self, parent) 
     self.parent = parent 
     self.initUI() 
... 

    def initUI(self): 
     self.outputBox = Text(bg='black', fg='green', relief=SUNKEN, yscrollcommand='TRUE') 
     self.outputBox.pack(fill='both', expand=True) 
     self.button1 = Button(self, text='button1', width=40, bg ='black', fg='green', activebackground='black', activeforeground='green') 
     self.button1.pack(side=RIGHT, padx=5, pady=5) 
     self.button2 = Button(self, text='button2', width=20, bg='black', fg='green', activebackground='black', activeforeground='green') 
     self.button2.pack(side=LEFT, padx=5, pady=5) 
... 

def main(): 
    root = Tk() 
    root.geometry('1100x350+500+300') 
    root.configure(background = 'black') 
    app = Application(root) 
    root.mainloop() 

root.configure(background = 'black')沒有改變根窗口的背景顏色...有什麼建議?

+0

嗯,你確定這是問題嗎? 'root.configure(background ='black')'在我的電腦上正常工作。 –

+0

你在使用什麼操作系統? – mgilson

+0

我使用的是Fedora 16 – user1435947

回答

7

這工作(檢查父根是如何引用):

編輯:我編輯的代碼和數字弄清其中的顏色設置:

from Tkinter import * 

class Application(Frame): 
    def __init__(self, master=None): 
     Frame.__init__(self, master) 
     self.parent = master 
     self.initUI() 

    def initUI(self): 
     self.outputBox = Text(self.parent, bg='yellow', height= 10, fg='green', relief=SUNKEN, yscrollcommand='TRUE') 
     self.outputBox.pack(fill='both', expand=True) 
     self.button1 = Button(self.parent, text='button1', width=20, bg ='blue', fg='green', activebackground='black', activeforeground='green') 
     self.button1.pack(side=RIGHT, padx=5, pady=5) 
     self.button2 = Button(self.parent, text='button2', width=25, bg='white', fg='green', activebackground='black', activeforeground='green') 
     self.button2.pack(side=LEFT, padx=5, pady=5) 

def main(): 
    root = Tk() 
    app = Application(root) 
    app.parent.geometry('300x200+100+100') 
    app.parent.configure(background = 'red') 
    app.mainloop() 

main() 

enter image description here

+0

編輯完成後,一切看起來都是一樣的... – user1435947

+0

您是否考慮過所有更改?檢查圖像。注意我使用了紅色背景 – joaquin

+0

是的......代碼確實有效,但背景仍然拒絕更改。也許我錯過了一個包的一部分?編輯:剛更新tkinter包,它仍然無法正常工作。 – user1435947

0

其「BG '。'配置行中'不'背景'。

+0

其實他們都工作 –