如何将QTimeEdit,QCheckBox和QDateTimeEdit的值转换为变量。 (蟒蛇)

时间:2015-08-27 18:07:14

标签: python python-3.x pyqt qt4 pyqt4

我从PyQt4开始,我正在制作一个练习计划。在该计划中,我有QDateTimeEditQTimeEditQCheckBox

如何使用信号和插槽将值从它们拉入字符串。

1 个答案:

答案 0 :(得分:0)

from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys


class main_frame(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)

        self.initUI()

    def initUI(self):

        # A push buttnon
        btn_get = QPushButton("Get Time", self)
        btn_get.move(100, 250)

        #       
        time = QTime()
        # Find what is the local/system time
        curent_t = time.currentTime()
        # Convert it to a str
        # The output shoud be HH:MM:SS  , eg 10:45:28
        curent_t_str = curent_t.toString()


        # Create a timeEdit widget 
        time_widget = QTimeEdit(time, self)
        time_widget.setTime(curent_t)

        def get_time():
            print(curent_t_str)

        btn_get.clicked.connect(get_time)


        ### At the end of the day you got curent_t_str variable
        ### which you can use it in your code down the road
        ### so I belive that`s helpful for your needs
        ### implement this may vary, depending your needs ...

        # Set a costom size for the mainWindow
        self.setFixedSize(300, 300)

def main():

    app = QApplication(sys.argv)
    myapp = main_frame()
    myapp.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()

这对你有帮助吗?请注意,对于 QDateTimeEdit ,过程是相同的,在您将值转换为格式如10:45:28后,您将如何格式化字符串或者您要使用的内容