如何打开一个新窗口,使我可以从以下代码中选择时间?我尝试使用connect函数连接到Windows2,但是似乎出现了错误。
我想通过一个保管箱选择时间,我可以在上午10点,上午11点等选择时间。还有谁知道您也可以实现这一点?
class Window(QMainWindow):
def __init__(self):
super().__init__()
self.label = QLabel()
self.calendar = QCalendarWidget()
self.title="Select date from calendar"
self.left = 600
self.top = 300
self.width = 500
self.height = 480
self.iconName = "home.png"
self.setWindowTitle(self.title)
self.setWindowIcon(QtGui.QIcon(self.iconName))
self.setGeometry(self.left, self.top, self.width, self.height)
self.proceedbutton = QPushButton("Proceed to select time", self)
self.proceedbutton.setGeometry(290, 430, 190, 40)
self.proceedbutton.setToolTip("<h3>Start the Session</h3>")
self.proceedbutton.clicked.connect(self.window2)
self.hide()
self.backbutton = QPushButton("Back", self)
self.backbutton.setGeometry(200, 430, 80, 40)
self.backbutton.setToolTip("<h3>Start the Session</h3>")
self.Calendar()
self.show()
def Calendar(self):
CalendarVbox = QVBoxLayout()
self.calendar.setGridVisible(True)
self.label.setFont(QtGui.QFont("Sanserif", 10))
self.label.setStyleSheet('color:black')
CalendarVbox.addWidget(self.calendar)
CalendarVbox.addWidget(self.label)
self.setLayout(CalendarVbox)
self.calendar.selectionChanged.connect(self.onSelectionChanged)
def window2(self):
self.label = QLabel("Select Time", self)
self.label.move(200,430)
self.setWindowTitle("Select Time")
self.setGeometry(self.left, self.top, self.width, self.height)
self.show()
def onSelectionChanged(self):
ca = self.calendar.selectedDate()
self.label.setText(ca.toString())
App = QApplication(sys.argv)
window = Window()
sys.exit(App.exec())