如何将 QTimeEdit、QCheckBox 和 QDateTimeEdit 的值放入变量中。 (Python)
How to get a value of QTimeEdit,QCheckBox and QDateTimeEdit into a variable. (Python)
我从 PyQt4 开始,我正在制作一个练习程序。在那个程序中,我有 QDateTimeEdit
、QTimeEdit
和 QCheckBox
。
我如何使用信号和槽将它们的值提取到字符串中。
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 的格式后,取决于您如何格式化字符串或您将使用什么
我从 PyQt4 开始,我正在制作一个练习程序。在那个程序中,我有 QDateTimeEdit
、QTimeEdit
和 QCheckBox
。
我如何使用信号和槽将它们的值提取到字符串中。
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 的格式后,取决于您如何格式化字符串或您将使用什么