【问题标题】:Dont show me again checkbox不再显示我复选框
【发布时间】:2016-07-30 11:34:05
【问题描述】:

我想要一个带有“不再显示”的窗口(顶层窗口)。如果选中此框,我不希望它再次显示此窗口。

import configparser
from tkinter import *
config = configparser.RawConfigParser()     #my ini file
config.add_section('Section1')
config.set('Section1', 'a_bool', 'False')
with open('settings.ini', 'w') as configfile:
    config.write(configfile)
root = Tk()
def var_states():                          #write to ini file
    global mt
    print(config.read('ayrlar.ini'))
    if var1 == True:
        config.set('Section1', 'a_bool', 'True')
        with open('settings.ini', 'w') as configfile:
            config.write(configfile)
        global window
        window.destroy()
    elif var1 == False:
        config.set('Section1', 'a_bool', 'False')
        with open('settings.ini', 'w') as configfile:
            config.write(configfile)
            global window
            window.destroy()
var1 = config.getboolean('Section1', 'a_bool')
def show():                           #if checkbox is true
    global window                     #dont show
    window= Toplevel(root)
    Checkbutton(window, text="Don't show me again", variable=var1).place(x=0, y=0)
    Button(window, text='Okey', command=var_states).place(x=0, y=25)
root.after(10,show)
root.mainloop()

再次运行时,我不想显示此窗口。我如何使用ConfigParser 做到这一点?

【问题讨论】:

  • Stack Overflow 不是代码编写服务。
  • 你可以看到我的代码我只想要我的代码问题为什么不工作

标签: python tkinter configparser


【解决方案1】:

要使Checkbutton 的变量起作用,它应该是IntVarBooleanVar。所以我用BooleanVar替换了你代码中的var1

def var_states():                          #write to ini file
    global mt
    print(config.read('ayrlar.ini'))
    if  var1.get():
        config.set('Section1', 'a_bool', 'True')
        with open('settings.ini', 'w') as configfile:
            config.write(configfile)
        global window
        window.destroy()
    else:
        config.set('Section1', 'a_bool', 'False')
        with open('settings.ini', 'w') as configfile:
            config.write(configfile)
            global window
            window.destroy()
var1 = BooleanVar(root, value=config.getboolean('Section1', 'a_bool'))

【讨论】:

    猜你喜欢
    • 2022-08-20
    • 2016-05-09
    • 1970-01-01
    • 2017-09-11
    • 2013-10-06
    • 1970-01-01
    • 1970-01-01
    • 2019-12-31
    • 1970-01-01
    相关资源
    最近更新 更多