如何在tkinter中摆脱背景中的灰色矩形?

时间:2018-07-25 10:53:19

标签: python tkinter

单击“单击我”按钮后,有一个灰色矩形,我找不到消除它的方法。我想知道是否有摆脱的方法。我要创建一个按钮,将整个窗口更改为其他按钮。我使用b8.pack_forget()摆脱了按钮,但单击按钮后在背景上留下了一个灰色矩形。 我的代码如下:

from tkinter import *
from tkinter import messagebox

win = Tk()
win.title('SaMpLe')
win.configure(background='dark turquoise', cursor='gumby')
f = Frame(win)

l = Label(win, text="WELCOME TO THE CLOUDS", bg='dark turquoise', fg='dark violet', font=('Small Fonts', 50))

l.pack()

def clicked():
    win.title("Rainbow")
    win.wm_iconbitmap('favicon.ico')
    win.configure(background="green2", cursor='star')
    f = Frame(win)#https://likegeeks.com/python-gui-examples-tkinter-tutorial/
    f2= Frame(win)


    #Commands
    def clicked1():
        win.configure(background="red")
        l.configure(bg="red", fg="red3")#change fg
        l2.configure(bg="red", fg="red3")
        messagebox.showinfo('Hello there, fellow user!', 'RED')


    def clicked2():
        win.configure(background="orange")
        l.configure(bg="orange", fg='gold')
        l2.configure(bg="orange", fg='gold')
        messagebox.showinfo('Hello there, fellow user!', 'ORANGE')


    def clicked3():
        win.configure(background="yellow")
        l.configure(bg="yellow", fg='yellow3')
        l2.configure(bg="yellow", fg='yellow3')
        messagebox.showinfo('Hello there, fellow user!', 'YELLOW')


    def clicked4():
        win.configure(background="green")
        l.configure(bg="green", fg='green2')
        l2.configure(bg="green", fg='green2')
        messagebox.showinfo('Hello there, fellow user!', 'GREEN')


    def clicked5():
        win.configure(background="blue")
        l.configure(bg="blue", fg='cyan')
        l2.configure(bg="blue", fg='cyan')
        messagebox.showinfo('Hello there, fellow user!', 'BLUE')



    def clicked6():
        win.configure(background="indigo")
        l.configure(bg="indigo", fg='SlateBlue2')
        l2.configure(bg="indigo", fg='SlateBlue2')
        messagebox.showinfo('Hello there, fellow user!', 'INDIGO')

    def clicked7():
        win.configure(background="dark violet")
        l.configure(bg="dark violet", fg='violet')
        l2.configure(bg="dark violet", fg='violet')
        messagebox.showinfo('Hello there, fellow user!', 'VIOLET')

    #Commands end

    b1 = Button(f,height = 1, width = 15, bg="red", fg="red", command=clicked1)
    b2 = Button(f, height = 1, width = 15, bg="orange", fg="orange", command=clicked2)
    b3 = Button(f, height = 1, width = 15, bg="yellow", fg="yellow", command=clicked3)
    b4 = Button(f, height = 1, width = 15, bg="green", fg="green", command=clicked4)
    b5 = Button(f, height = 1, width = 15, bg="blue", fg="blue", command=clicked5)
    b6 = Button(f, height = 1, width = 15, bg="indigo", fg="indigo", command=clicked6)
    b7 = Button(f, height = 1, width = 15, bg="dark violet", fg="dark violet", command=clicked7)

    b1.pack(side=LEFT)
    b2.pack(side=LEFT)
    b3.pack(side=LEFT)
    b4.pack(side=LEFT)
    b5.pack(side=LEFT)
    b6.pack(side=LEFT)
    b7.pack(side=LEFT)

    b8.pack_forget()
    l.configure( text="CLICK THE BUTTONS BELOW TO", fg="magenta2",bg="green2", font=("@Fixedsys", 50))
    l2=Label(win, text="LEARN THE COLOURS OF THE RAINBOW!", fg="yellow",bg="green2", font=('@fixedsys', 50))
    l2.pack()
    f.pack()

b8= Button(f,text = 'CLICK ME!', height = 1, width = 15, bg='green2', fg='magenta', command=clicked)
b8.pack()
f.pack()

0 个答案:

没有答案