self.checkBox_drank.stateChanged.connect(self.checkBox_drank_choose) def checkBox_drank_choose(self): if self.checkBox_drank.isChecked(): with open("c:\timerXdd\setupcheckboxDrank.txt", mode='w', encoding='utf-8') as ff: ff.writelines('1') else: with open("c:\timerXdd\setupcheckboxDrank.txt", mode='w', encoding='utf-8') as ff: ff.writelines('0')