2012-06-04 172 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

其实他们都工作 –