当我创建一个框架并为其设置背景颜色时,颜色会很好地显示出来。但是,当我向框架添加一个小部件时,背景颜色会消失。我尝试将相同的颜色设置为小部件的背景,但框架中仍然有许多白点。
以下是无效的代码块:
DAC_frame = Frame(self, width=180, height=240, bg="red")
DAC_frame.pack(side=RIGHT)
DAC_delete_label = Label(DAC_frame, text="Delete A Term:", bg="red")
DAC_delete_label.pack(fill=X)
DAC_delete_entry = Entry(DAC_frame)
DAC_delete_entry.pack()
DAC_delete = Button(DAC_frame, text="Delete Term")
DAC_delete.pack()
DAC_clear = Button(DAC_frame, text="Clear Dictionary")
DAC_clear.pack()
答案 0 :(得分:0)
您无法在Tkinter中设置透明色,这就是Frame
背景消失的原因。所以"白点"只是你的小部件的背景。您现在有两个选择:
Canvas
here is a example 为每个小部件设置相同的backgroundcolor,对于可以将borderwidth
设置为0的按钮。
from Tkconstants import RIGHT, X
from Tkinter import Frame, Tk, Label, Entry, Button
import Tkinter
class App(Tk):
def __init__(self):
Tkinter.Tk.__init__(self)
DAC_frame = Frame(self, width=180, height=240, bg="red")
DAC_frame.pack(side=RIGHT)
DAC_delete_label = Label(DAC_frame, text="Delete A Term:", bg="red")
DAC_delete_label.pack(fill=X)
DAC_delete_entry = Entry(DAC_frame)
DAC_delete_entry.pack()
DAC_delete = Button(DAC_frame, text="Delete Term",borderwidth=0, bg="red", activebackground="red")
DAC_delete.pack()
DAC_clear = Button(DAC_frame, text="Clear Dictionary",borderwidth=0, bg="red", activebackground="red")
DAC_clear.pack()
ap = App()
ap.mainloop()