Graphical interface with python # 5 - Checkbox

Опубликовано: 29 Сентябрь 2024
на канале: Professor Neto Paschoal
1,820
64

Learn how to create graphical interface with python using the tkinter library. In this class is taught how to create a checkbox, element that is widely used in forms and other applications.

code:

from tkinter import *
janela = Tk()

def funcao():
if var_azul.get() == 1:
l1["text"]= "azul"
else:
l1["text"] = ""
if var_branco.get() == 1:
l2["text"] = "branco"
else:
l2["text"] = ""
if var_vermelho.get() == 1:
l3["text"] = "vermelho"
else:
l3["text"] = ""
if var_amarelo.get() == 1:
l4["text"] = "amarelo"
else:
l4["text"] = ""

l1 = Label(janela,text="",font="Arial 22",background="light blue",foreground="blue")
l1.place(x=200,y=50)
l2 = Label(janela,text="",font="Arial 22",background="light blue",foreground="white")
l2.place(x=350,y=50)
l3 = Label(janela,text="",font="Arial 22",background="light blue",foreground="red")
l3.place(x=500,y=50)
l4 = Label(janela,text="",font="Arial 22",background="light blue",foreground="yellow")
l4.place(x=650,y=50)


var_azul= IntVar()
Checkbutton(janela,text="azul",background="light blue",variable= var_azul).place(x=300,y=200)
var_branco= IntVar()
Checkbutton(janela,text="branco",background="light blue",variable= var_branco).place(x=300,y=230)
var_vermelho= IntVar()
Checkbutton(janela,text="vermelho",background="light blue",variable= var_vermelho).place(x=300,y=260)
var_amarelo= IntVar()
Checkbutton(janela,text="amarelo",background="light blue",variable= var_amarelo).place(x=300,y=290)

Button(janela,text="verifa cor",command=funcao,background="blue").place(x=300,y=350)





janela.geometry("900x600+0+0")
janela.configure(background="light blue")
janela.mainloop()