0

¿ hay alguna forma de que un Checkbutton aparezca ya activo por defecto?. Pongo un trozo del código para que se vea como genero los interruptores:

import tkinter
root = tkinter.Tk () 
root.title ("Grafic")
root.state('zoomed')
frame1=Frame(root)
frame1.pack(fill='both', expand=1) 
frame1.config(bg='white') 
Checkbutton(frame1, text="canal 1 ",bg='red',  width=5,height=1, onvalue=1,relief='groove', bd=10,
            offvalue=0).pack()
Checkbutton(frame1, text="canal 2 ",bg='blue',  width=5,height=1,  onvalue=1,relief='groove', bd=10,
            offvalue=0).pack()
root.mainloop()

1 respuesta 1

1

No puede establecer un estado de un control de casilla de verificación sin una variable booleana, usted debe usar una variable para cambiar el estado entre True o False, por tanto lógicamente usar una variable puede establecer el estado predeterminado del control.

Por tanto quedaría así con base en su código:

import tkinter
import tkinter as tk
root = tkinter.Tk () 
root.title ("Grafic")
root.state('zoomed')
frame1=tk.Frame(root)
frame1.pack(fill='both', expand=1) 
frame1.config(bg='white')
VariableControl1 = tk.IntVar() # Variable 1
tk.Checkbutton(frame1, text="canal 1 ",bg='red',  width=5,height=1, variable=VariableControl1,relief='groove', bd=10).pack()
VariableControl1.set(1) # Activo por defecto variable 1

VariableControl2 = tk.IntVar() # Variable 2
tk.Checkbutton(frame1, text="canal 2 ",bg='blue',  width=5,height=1,relief='groove', bd=10,
            variable=VariableControl2).pack()
VariableControl2.set(0) # No activo por defecto variable 2
root.mainloop()

La variable IntVar() establece verdadero o falso mendiante un valor entero, BooleanVar() es simlar solo acepta más que entre True o False.

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.