如何在Pygubu中设置复选框状态

2024-05-29 07:33:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经试着通过代码设置tkinter复选框状态有一段时间了,我被卡住了。你知道吗

尝试了.toggle().set().select()但是我得到了“对象没有属性”

在使用pygubu时,是否有其他方法访问tkinter对象方法?你知道吗

有什么办法吗?你知道吗

import os
import tkinter as tk  # for python 3
import pygubu

CURDIR = os.path.dirname(__file__)
UI_FILE = os.path.join(CURDIR, 'gui2.ui')

class Application:
    def __init__(self):
        #1: Create a builder
        self.builder = builder = pygubu.Builder()
        #2: Load an ui file
        builder.add_from_file(UI_FILE)
        #3: Create the widget using a master as parent
        self.mainwindow = builder.get_object('toplevel1')
         #4: connect callbacks
        self.builder.connect_callbacks(self)

    def on_print(self):
        checked = self.builder.get_object('Checkbutton_1')
        checked.toggle()

    def run(self):
        self.mainwindow.mainloop()

if __name__ == '__main__':
    app = Application()
    app.run()

Tags: path对象方法importselfuiostkinter

热门问题