简体   繁体   English

python ttk选中的checkbutton

[英]python ttk checked checkbutton

i'm trying to start a program with the checkbutton selected but I don't know how to do it. 我试图用选中的按钮启动程序,但我不知道该怎么做。

import tkinter as tk
from tkinter import ttk
root = tk.Tk()
v = tk.IntVar()
cb = ttk.Checkbutton(root,text='Remember user',onvalue=1,offvalue=0, variable = v);cb.pack()

Use the select() method: 使用select()方法:

from tkinter import *

root = Tk()
cb = Checkbutton(root,text='Remember user',onvalue=1,offvalue=0)
cb.pack()
cb.select()

One can simply instantiate the variable with a desired value, such as 1 : 可以简单地实例化具有所需值的变量,例如1

v = tk.IntVar(value=1)

which is the same onvalue represented by cb . 这与cb表示的onvalue相同。 Since its value and v is the very same, and since v is the attached variable , it will be selected from the very beginning. 因为它的值和v是非常相同的,并且因为v是附加variable ,所以将从一开始就选择它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM