V
V
Vladimir Adam2019-02-18 15:02:54
Python
Vladimir Adam, 2019-02-18 15:02:54

How to create CheckBox on click?

Code I am using:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from PyQt5.QtWidgets import QWidget
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtWidgets import QCheckBox

from PyQt5.QtGui import QFont


class OpenChecker(QWidget):

    def __init__(self):
        super().__init__()
        self.initUI()
    
    def initUI(self):
        self.setWindowTitle("OpenChecker")
        self.setFixedSize(800, 600)

        self.save = QPushButton("Save", self)
        self.save.setFont(QFont("SansSerif", 10))
        self.save.clicked.connect(self.save_task)
        self.save.resize(self.save.sizeHint())
        self.save.move(290,10)

        self.load = QPushButton("Load", self)
        self.load.setFont(QFont("SansSerif", 10))
        self.load.clicked.connect(self.load_task)
        self.load.resize(self.load.sizeHint())
        self.load.move(380,10)

        self.show()

    def save_task(self):
        print(1)

    def load_task(self):
        self.checkbox = QCheckBox("hello", self)
        self.checkbox.move(0,0)

Problem: The checkbox is not added to the program window.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2019-02-19
@binxpy

Try calling self.checkbox.show() after the object has been created (self.checkbox = QCheckBox("hello", self)).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question