LCD Widget

Final Result

C3:Date and Time

How to do it?

class MyForm(QDialog):
    def __init__(self):
        super().__init__()
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        timer = QtCore.QTimer(self)
        timer.timeout.connect(self.showlcd)
        timer.start(1000)
        self.showlcd()
    def showlcd(self):
        time = QtCore.QTime.currentTime()
        text = time.toString('hh:mm')
        self.ui.lcdNumber.display(text)
if __name__=="__main__":
    app = QApplication(sys.argv)
    w = MyForm()
    w.show()
    sys.exit(app.exec_())

Date Edit Widget

Final Result

C3:Date and Time

How to do it?

class MyForm(QDialog):
    def __init__(self):
        super().__init__()
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.ui.calendarWidget.selectionChanged.connect(self.dispdate)
        self.show()
    def dispdate(self):
        self.ui.dateEdit.setDisplayFormat("yyyy MMM d")
        self.ui.dateEdit.setDate(self.ui.calendarWidget.selectedDate())
if __name__=="__main__":
    app = QApplication(sys.argv)
    w = MyForm()
    w.show()
    sys.exit(app.exec_())

Create Hotel Reservation Form

Final Result

C3:Date and Time

How to do it?

class MyForm(QDialog):
    def __init__(self):
        super().__init__()
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.roomtypes=['suite','super luxury','super deluxe','ordinary']
        self.addcontent()
        self.ui.pushButton.clicked.connect(self.computeRoomRent)
        self.show()
    def addcontent(self):
        for i in self.roomtypes:
            self.ui.comboBox.addItem(i)
    def computeRoomRent(self):
        dateselected = self.ui.calendarWidget.selectedDate()
        dateinstring = str(dateselected.toPyDate())
        noOfDays = self.ui.spinBox.value()
        chosenRoomType = self.ui.comboBox.itemText(self.ui.comboBox.currentIndex())
        self.ui.message.setText("Date of reservation: "+dateinstring+" , Number of days : "+ str(noOfDays) + " and Room type selected : " + chosenRoomType )
        roomRent = 0
        if chosenRoomType == "suite":
            roomRent=40
        if chosenRoomType=="super luxury":
            roomRent=30
        if chosenRoomType=="super deluxe":
            roomRent=20
        if chosenRoomType=="ordinary":
            roomRent=10
        total = roomRent*noOfDays
        self.ui.message1.setText("Room Rent for single day for "+chosenRoomType+" type is "+str(roomRent)+"$.nTotal room rent is "+str(total))
if __name__=="__main__":
    app = QApplication(sys.argv)
    w = MyForm()
    w.show()
    sys.exit(app.exec_())

Table Widget Item

Final Result

C3:Date and Time

C3:Date and Time

How to do it?

class MyForm(QDialog):
    def __init__(self,data):
        super().__init__()
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.data = data
        self.addcontent()
    def addcontent(self):
        row = 0
        for tup in self.data:
            col=0
            for item in tup:
                oneitem = QTableWidgetItem(item)
                self.ui.tableWidget.setItem(row,col,oneitem)
                col+=1
            row+=1
data=[]
data.append(("suite",'$40'))
data.append(("super luxury",'$30'))
data.append(("super deluxe",'$20'))
data.append(("ordinary",'$10'))
if __name__=="__main__":
    app = QApplication(sys.argv)
    w = MyForm(data)
    w.show()
    sys.exit(app.exec_())

 

 

相关文章: