Python GTK : How to make it so a checkbox determines if a window will open or not

标签 python linux terminal gtk

在我的程序中,我有一个烦人的弹出窗口,提醒用户检查设置。我有一个复选框,如果选中该复选框,则应该永远不会再显示弹出窗口。我不知道该怎么做。选中该复选框后,我需要程序写入一个名为 tog_file.txt 的文本文件,并显示“true”。如果 tog_file.txt 中的文本为 true,则弹出窗口将不再显示。 代码:

def reminder():
    global tog
    tog = open("tog_file.txt", "r+b")
    tog_r = tog.read()
    if tog_r == "true":
        print "true"
    if tog_r == "":
        global reminder
        reminder = gtk.Window(gtk.WINDOW_TOPLEVEL)
        reminder.set_position(gtk.WIN_POS_CENTER)
        reminder.set_size_request(450, 205)
        reminder.set_title("Info")

        textbox = gtk.Label("Remember To Go Into The Settings Menu! There are Important Settings that Need to be Reviewed by you!")
        textbox.set_justify(gtk.JUSTIFY_CENTER) 
        textbox.set_line_wrap(True)   

        button = gtk.Button("Close")
        button.connect("clicked", reminder_close)

        toggle = gtk.CheckButton("Don't Show This Message Again")
        item_text = toggle.get_active()
        if item_text == False:
            print "no"
        if item_text == True:
            print "yea"
            tog.write("true")

        fixed = gtk.Fixed()
        fixed.put(button, 300, 160)
        fixed.put(toggle, 50, 165)
        fixed.put(textbox, 50, 50)

        reminder.add(fixed)
        reminder.show_all()

def reminder_close(self):
    reminder.destroy()

如果您需要任何其他信息,请发表评论。 感谢 StackOverflow :)

最佳答案

我认为您需要 get_active() 方法。检查是否button.get_active() => boolean 并采取相应的行动。您还可以将 radio bt 连接到“toggle”信号,并在 on_toggle 函数中设置具有 bt 状态的类变量: if bt.get_active():self.ischeck=True else:self.ischeck = False 或简短的方式:self.ischeck = True if bt.get_active() else False

关于Python GTK : How to make it so a checkbox determines if a window will open or not,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24268213/

相关文章:

python - 为什么我的基本 PyGame 模块这么慢?

python - 如何从后台运行的脚本返回命令行

shell - 将 csv 文件的前 x 行读取到新的输出文件中?

bash - 将前缀 key 发送到 tmux session

python - 如何在终端(ubuntu)上运行 python 脚本?

python - 用于忽略搜索中的字符的正则表达式

python - 添加额外的循环会导致无响应

python - 错误请求错误 : app "dev~myapp" cannot access app "s~myapp"'s data

php - Wsdl curl 错误 7 : couldn't connect to host

linux - 使用 su 执行 Node 程序时权限被拒绝