如何将QTimeEdit、QCheckBox和QDateTimeEdit的值获取到变量中。(Python)

2024-05-13 18:48:40 发布

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

我从PyQt4开始,我正在制作一个练习程序。在那个程序中,我有QDateTimeEditQTimeEdit和{}。在

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


Tags: 字符串程序信号插槽pyqt4将值qtimeeditqdatetimeedit
1条回答
网友
1楼 · 发布于 2024-05-13 18:48:40
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这样的格式之后,您将如何格式化字符串或使用什么

相关问题 更多 >