Skip to content

Instantly share code, notes, and snippets.

@rodrigo-x
Last active August 4, 2021 14:55
Show Gist options
  • Save rodrigo-x/118585ab3cd4a9dfce819cf682a3576f to your computer and use it in GitHub Desktop.
Save rodrigo-x/118585ab3cd4a9dfce819cf682a3576f to your computer and use it in GitHub Desktop.
import tkinter as tk
from tkinter import ttk
from ttkthemes import ThemedTk
# Crio a janela e acrescento o tema radiance
root = ThemedTk(theme = 'radiance')
"""
Função que brinca com a lógica vinda das Checkbuttons
O .get() pega o que vem do tk.IntVar() e compara
Com o resultado:
1 - se estiver clicado
0 - se não estiver
"""
def check_callback():
if (char_un.get() == 1):
label.configure(text = 'Python é o melhor!')
elif (char_dis.get() == 1):
label.configure(text = 'C++ é o melhor!')
elif (char_un.get() == 0 and char_dis == 0):
label.configure(text = 'Os dois são bons!')
else:
label.configure(text = 'Os dois são bons!')
label = ttk.Label(root, width = '20', text = 'Selecione o checkbox!') # Crio a label
label.place(x = '30', y = '30') # Coloco no lugar
char_un = tk.IntVar() # Pego o resultado que é um número inteiro
check = ttk.Checkbutton(root, text = 'Python', variable = char_un,
command = check_callback) # crio o Checkbutton na window
check.place(x = '30', y = '80') # Coloco no lugar
char_dis = tk.IntVar() # Pego o resultado do checkbutton
check1 = ttk.Checkbutton(root, text = 'C++', variable = char_dis,
command = check_callback) # Crio o checkbutton
check1.place(x = '30', y = '120') # Coloco no lugar na window
# Crio o button já estilizado..
botao = ttk.Button(root, text = 'fechar', command = root.destroy)
botao.place(x = '30', y = '165') # Coloco no lugar
# método Factory da window
root.title('Enquete - votação') # Título da window
root.config(background = '#f8f4f4') # Cor de fundo
root.geometry('300x250')
root.resizable(False, False)
root.iconbitmap(r'home\rodrigo\checklist.ico')
root.eval('tk::PlaceWindow . center') # Centralizo a Window
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment