Hi
I made a timer program. Where you write the time in some text boxes and when the clock hits that time
it should show a messagebox. But my problem is the messagebox crashes. i have no ide why.
could anyone help me?
I made a timer program. Where you write the time in some text boxes and when the clock hits that time
it should show a messagebox. But my problem is the messagebox crashes. i have no ide why.
could anyone help me?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
import sys from datetime import datetime from threading import Timer from PySide2.QtUiTools import QUiLoader from PySide2.QtWidgets import QApplication, QPushButton, QLineEdit, QMessageBox from PySide2.QtCore import QFile, QObject class Form(QObject): def __init__( self , ui_file, parent = None ): super (Form, self ).__init__(parent) ui_file = QFile(ui_file) ui_file. open (QFile.ReadOnly) loader = QUiLoader() self .window = loader.load(ui_file) ui_file.close() self .timmar = self .window.findChild(QLineEdit, 'timmar' ) self .minuter = self .window.findChild(QLineEdit, 'minuter' ) self .sekunder = self .window.findChild(QLineEdit, 'sekunder' ) self .textmsg = self .window.findChild(QLineEdit, 'textmsg' ) btn = self .window.findChild(QPushButton, 'pushButton' ) btn.clicked.connect( self .ok_handler) self .window.show() def ok_handler( self ): timmarValue = int ( self .timmar.text()) minuterValue = int ( self .minuter.text()) sekunderValue = int ( self .sekunder.text()) x = datetime.today() y = x.replace(day = x.day + 1 , hour = timmarValue, minute = minuterValue, second = sekunderValue, microsecond = 0 ) delta_t = y - x secs = delta_t.seconds + 1 t = Timer(secs, self .hello_world) t.daemon = True t.start() def hello_world( self ): textmsg = self .textmsg.text() print (textmsg) msgBox = QMessageBox() msgBox.setIcon(QMessageBox.Information) msgBox.setText( "Message box pop up window" ) msgBox.setWindowTitle( "QMessageBox Example" ) msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) returnValue = msgBox. exec () if returnValue = = QMessageBox.Ok: print ( 'OK clicked' ) if __name__ = = '__main__' : app = QApplication(sys.argv) form = Form( 'time2gui.ui' ) sys.exit(app.exec_()) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
<?xml version = "1.0" encoding = "UTF-8" ?> <ui version = "4.0" > < class >Form< / class > <widget class = "QWidget" name = "Form" > < property name = "geometry" > <rect> <x> 0 < / x> <y> 0 < / y> <width> 272 < / width> <height> 165 < / height> < / rect> < / property > < property name = "windowTitle" > <string>Form< / string> < / property > <widget class = "QWidget" name = "layoutWidget" > < property name = "geometry" > <rect> <x> 10 < / x> <y> 10 < / y> <width> 251 < / width> <height> 141 < / height> < / rect> < / property > <layout class = "QVBoxLayout" name = "verticalLayout_8" > <item> <layout class = "QVBoxLayout" name = "verticalLayout_7" > <item> <layout class = "QGridLayout" name = "gridLayout" > <item row = "0" column = "0" > <layout class = "QVBoxLayout" name = "verticalLayout" > <item> <widget class = "QLabel" name = "label_3" > < property name = "text" > <string>H< / string> < / property > < property name = "alignment" > < set >Qt::AlignCenter< / set > < / property > < / widget> < / item> <item> <widget class = "QLineEdit" name = "timmar" > < property name = "alignment" > < set >Qt::AlignCenter< / set > < / property > < / widget> < / item> < / layout> < / item> <item row = "0" column = "1" > <layout class = "QVBoxLayout" name = "verticalLayout_2" > <item> <widget class = "QLabel" name = "label_4" > < property name = "text" > <string>:< / string> < / property > < property name = "alignment" > < set >Qt::AlignCenter< / set > < / property > < / widget> < / item> <item> <widget class = "QLabel" name = "label" > < property name = "text" > <string>:< / string> < / property > < property name = "alignment" > < set >Qt::AlignCenter< / set > < / property > < / widget> < / item> < / layout> < / item> <item row = "0" column = "2" > <layout class = "QVBoxLayout" name = "verticalLayout_3" > <item> <widget class = "QLabel" name = "label_5" > < property name = "text" > <string>M< / string> < / property > < property name = "alignment" > < set >Qt::AlignCenter< / set > < / property > < / widget> < / item> <item> <widget class = "QLineEdit" name = "minuter" > < property name = "alignment" > < set >Qt::AlignCenter< / set > < / property > < / widget> < / item> < / layout> < / item> <item row = "0" column = "3" > <layout class = "QVBoxLayout" name = "verticalLayout_4" > <item> <widget class = "QLabel" name = "label_7" > < property name = "text" > <string>:< / string> < / property > < property name = "alignment" > < set >Qt::AlignCenter< / set > < / property > < / widget> < / item> <item> <widget class = "QLabel" name = "label_2" > < property name = "text" > <string>:< / string> < / property > < property name = "alignment" > < set >Qt::AlignCenter< / set > < / property > < / widget> < / item> < / layout> < / item> <item row = "0" column = "4" > <layout class = "QVBoxLayout" name = "verticalLayout_5" > <item> <widget class = "QLabel" name = "label_6" > < property name = "text" > <string>S< / string> < / property > < property name = "alignment" > < set >Qt::AlignCenter< / set > < / property > < / widget> < / item> <item> <widget class = "QLineEdit" name = "sekunder" > < property name = "alignment" > < set >Qt::AlignCenter< / set > < / property > < / widget> < / item> < / layout> < / item> < / layout> < / item> <item> <layout class = "QVBoxLayout" name = "verticalLayout_6" > <item> <widget class = "QLabel" name = "label_8" > < property name = "text" > <string>Text Meddelande< / string> < / property > < property name = "alignment" > < set >Qt::AlignCenter< / set > < / property > < / widget> < / item> <item> <widget class = "QLineEdit" name = "textmsg" / > < / item> < / layout> < / item> < / layout> < / item> <item> <widget class = "QPushButton" name = "pushButton" > < property name = "text" > <string>Start< / string> < / property > < / widget> < / item> < / layout> < / widget> < / widget> <resources / > <connections / > < / ui> |