选中另一个复选框后,取消选中这些复选框

时间:2019-06-08 00:54:46

标签: python tkinter

所以问题出在if函数上,它根本无法工作。它完全忽略所有值更改,并且根本不更改任何值。此代码有什么问题?

import tkinter as tk
root = tk.Tk()

CheckVar4 = tk.IntVar()
CheckVar5 = tk.IntVar()

C4 = tk.Checkbutton(root, text = "Medium terms", variable = CheckVar4, \
                 onvalue = 1, offvalue = 0, height=1, \
                 width = 12)

C5 = tk.Checkbutton(root, text = "Hard terms", variable = CheckVar5, \
                 onvalue = 1, offvalue = 0, height=1, \
                 width = 8)

if CheckVar4.get() == 1:
    CheckVar5.set(0)

if CheckVar5.get() == 1:
    CheckVar4.set(0)

root.mainloop()

1 个答案:

答案 0 :(得分:1)

也许想改用单选按钮?来自here的以下示例:

// This is how you create embed token with effective identities
                    if (!string.IsNullOrWhiteSpace(username))
                    {
                        var rls = new EffectiveIdentity(username, new List<string> { report.DatasetId });
                        if (!string.IsNullOrWhiteSpace(roles))
                        {
                            var rolesList = new List<string>();
                            rolesList.AddRange(roles.Split(','));
                            rls.Roles = rolesList;
                        }
                        // Generate Embed Token with effective identities.
                        generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view", identities: new List<EffectiveIdentity> { rls });
                    }