(Tkinter) How to leave Labels, Buttons, and Frames with the tranparente background?

Asked

Viewed 378 times

0

I’m trying to make a program in Python with Tkinter to make records and so on, but when trying to put a photo in the background image it is impossible to remove the white spaces that Tkinter does when you create a label and bd boot, or a button.O app aberto. The master class with details that can help

class Window1:
    def __init__(self, master):
        self.master = master
        self.master.title("UnderFox")
        self.master.geometry('1350x750+0+0')
        self.master.iconbitmap("fox.ico")
        self.image = PhotoImage(file="download.png")
        self.image = self.image.subsample(1,1)
        self.labelimage = Label(image=self.image)
        self.labelimage.place(x=0, y=0, relwidth=1.0, relheight=1.0)
        self.frame = Frame(self.master)
        self.frame.pack()

        self.User = StringVar()
        self.Password = StringVar()
        self.LabelTitle = Label(self.frame, text="Registro Geral", font=('arial', 50,'bold'), bd=20)
        self.LabelTitle.grid(row=0, column=0, columnspan=2, pady=20)

        self.Loginframe1 = Frame(self.frame, width=1010, height=300, bd=20, relief='ridge')
        self.Loginframe1.grid(row=1, column=0)
        self.Loginframe2 = Frame(self.frame, width=1010, height=100, bd=20, relief='ridge')
        self.Loginframe2.grid(row=2, column=0)
        self.Loginframe3 = Frame(self.frame, width=1010, height=200, bd=20,  relief='ridge')
        self.Loginframe3.grid(row=3, column=0, pady=2)

        self.LabelUser = Label(self.Loginframe1, text="Nome", font=('arial', 30,'bold'), bd=22)
        self.LabelUser.grid(row=0, column=0)
        self.txtUser = Entry(self.Loginframe1, text="Nome", font=('arial', 30, 'bold'), bd=22, textvariable=self.User)
        self.txtUser.grid(row=0, column=1)


        self.LabelPassword = Label(self.Loginframe1, text="Senha", font=('arial', 30, 'bold'), bd=22)
        self.LabelPassword.grid(row=1, column=0)
        self.txtPassword = Entry(self.Loginframe1, text="Senha", font=('arial', 30, 'bold'), bd=22, textvariable=self.Password)
        self.txtPassword.grid(row=1, column=1)
        self.btnLogin = Button(self.Loginframe2, text='Login', width=17,font=('arial',20,'bold'), command=self.Login_System)
        self.btnLogin.grid(row=0, column=0)

        self.btnReset = Button(self.Loginframe2, text='Resetar', width=17, font=('arial',20,'bold'), command=self.Reset)
        self.btnReset.grid(row=0, column=1)

        self.btnExit = Button(self.Loginframe2, text='Sair',  width=17, font=('arial',20,'bold'), command=self.iExit)
        self.btnExit.grid(row=0, column=2)


        self.btnResgistration = Button(self.Loginframe3, text='Registro Infantil', font=('arial',20,'bold'), state = DISABLED, command=self.resgistration_window)
        self.btnResgistration.grid(row=0, column=0)

        self.btnHospital = Button(self.Loginframe3, text='Registro Equipe DI', font=('arial',20,'bold'), state=DISABLED,  command=self.hospital_window)
        self.btnHospital.grid(row=0, column=1)

1 answer

1

Tkinter does not support transparency - so unfortunately there is no such thing as.

You can create themes with gradients, fake reflexes, do a lot of things - but it has neither text rotation nor transparency - it exposes a drawing API created decades ago - it was and is stable, works well, but has not evolved in graphic questions.

So it’s not possible to say that the 'frame' where you mount your controls has transparent or translucent background - if it exists, it has to have a solid color.

What is possible, however, but not simple, is not use frame, and add all controls directly into the main window (master) - just don’t use the self.frame and always pass self.master in its place, and try to use the options padx, pady, ipadx and ipady in your controls to try to arrive at a nice layout (these are options that can be passed the call .grid in addition to information from row and column)

  • OK! Thank you very much, I really thought there was a way to do this, I will try to use self.master. But if I understood I would have to remove the frames, using the master, and put on each label, button and etc, its specific position, and then in this case disappear the white parts, correct?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.