簡體   English   中英

Python / Tkinter根窗口后台配置

[英]Python/Tkinter root window background configuration

我正在嘗試創建一個黑色背景的根窗口,以與我的按鈕背景混合。

我有以下內容:

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')沒有改變根窗口的背景顏色......有什么建議嗎?

這有效(檢查如何引用父根):

編輯:我編輯了代碼和圖形,以明確設置顏色的位置:

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()

在此輸入圖像描述

它的'bg'不是.configure行中的'background'。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM