因此,我有一个简单的tkinter窗口,可使用画布创建一个简单的渐变。我遇到的问题是,每当将小部件放置在窗口上时,它们的背景就会出现。我尝试弄乱窗口属性,但没有成功。任何想法将不胜感激
import tkinter as tk
root = tk.Tk()
full_width, full_height = (root.winfo_screenwidth()), (root.winfo_screenheight())
def Startup(): #Gradient Left to right
root.overrideredirect(True)
root.lift()
root.geometry('%dx%d+0+0' % (full_width,full_height))
colour1 = "#d785a5"
colour2 = "#6b3d8f"
width = root.winfo_screenwidth()
height = root.winfo_screenheight()
(r1,g1,b1) = root.winfo_rgb(colour1)
(r2,g2,b2) = root.winfo_rgb(colour2)
r_ratio = float(r2-r1) / full_width
g_ratio = float(g2-g1) / full_width
b_ratio = float(b2-b1) / full_width
c = tk.Canvas(root, width = full_width, height = full_height)
c.pack(side = tk.TOP, expand = True, fill = "both")
c.update()
for i in range(full_width):
nr = int(r1 + (r_ratio * i))
ng = int(g1 + (g_ratio * i))
nb = int(b1 + (b_ratio * i))
colour = "#%4.4x%4.4x%4.4x" % (nr,ng,nb)
c.create_line(i, 0, i, full_height, fill = colour)
root.option_add("*Font", "Helvetica")
tk.Label(c, font=("Colonna MT", round(full_height/10)),text="Log in").pack()
tk.Label(c,text="").pack()
tk.Label(c,text="Username").pack()
tk.Label(c,text="").pack()
t = tk.Entry(c)
t.pack()
tk.Label(c,text="").pack()
tk.Label(c,text="Password").pack()
tk.Label(c,text="").pack()
t2 = tk.Entry(c, show='*')
t2.pack()
tk.Label(c,text="").pack()
tk.Button(c, text='Login', command= lambda:retrieve_input(t,t2)).pack()
Startup()