[Python interface applet] Note The holiday train ticket query system has been completed, please pay attention to here →

Introduction

Weekends and holidays are coming, Qixi Festival is coming soon, and it’s the most difficult time of the year to get tickets!

Those little cuties who want to go home during the holidays and have long-distance relationships during the holidays, can they grab the city tickets for going home (dates) on time?

The complete material + source code of all articles are in 👇👇

*****[Fans who prostitute source code benefits, please move to the CSDN community or the public at the end of the article for free.]*****

In order to let everyone reunite with relatives, friends and family as soon as possible, the editor bravely came out this year to remind everyone to grab train tickets early!

(I don’t want to wait for the time. When there are tickets, the demons should buy them in advance~ Otherwise, there will be no tickets in the sales department at that time.)

I specially wrote a code-based Python-based train ticket query system with an interface for you to query anytime, anywhere, or go to special purchase

Ask where the tickets are, and it’s a hassle to go without a ticket—if you have a ticket, remember to buy it early!

Note: You need to learn it if you need it or not. If you use it someday, it’s not a loss if you learn it!

text

1. Operating environment

The environment used by the editor: Python3, Pycharm Community Edition, requests, PyQt5 modules, some of them are not one by one

Show it.

import re
import urllib
from urllib import request
# from pprint import pprint
url = 'https://kyfw.12306.cn/otn/resources/js/framework/station_name.js?station_version=1.9048'
req = urllib.request.Request(url)
r = urllib.request.urlopen(req).read().decode('utf-8')
stations =re.findall( r'([\u4e00-\u9fa5]+)\|([AZ]+)' ,r)     # Match Chinese and corresponding English 
stations = dict(stations)      # Convert to dictionary 
# pprint( stations) # print out in columns

Second, the code display

1) Crawling data

'''
Train ticket inquiry system
'''
__author__ = 'Scorpio'
import sys
from PyQt5.QtCore import Qt,QDateTime
from PyQt5.QtWidgets import QWidget,QMessageBox,QApplication,QLabel,QTableWidget,QLineEdit,QHBoxLayout,QGridLayout,QVBoxLayout,QPushButton,QTableWidgetItem,QFrame,QDateTimeEdit
from PyQt5.QtGui import QFont,QColor,QBrush
from get_stations import stations
import warnings
import requests
class TableSheet(QWidget):
    def __init__(self):
        super().__init__()
        self.initUi()

    def  initUi (self) : 
        #self.setWindowFlags(Qt.WindowCloseButtonHint && Qt.WindowMinimizeButtonHint) 
        #self.setWindowFlags(Qt.WindowMinimizeButtonHint) 
        self.setWindowTitle( 'Train ticket query system' )
         #self.setGeometry(40,80,1500, 720) #The 
        first part, enter the origin, destination and date 
        controlsLayout = QGridLayout()       #Grid layout 
        self.label1 = QLabel( "Departure:" )
        self.Editlabel1 = QLineEdit()
        self.label2 = QLabel( "Destination:" )
        self.Editlabel2 = QLineEdit()
        self.label3 = QLabel( "Ride date: " )

        self.Editlabel3 = QDateTimeEdit()
        now = QDateTime.currentDateTime()
        #print(now)
        self.Editlabel3.setDateTime(now)
        self.Editlabel3.setDisplayFormat( "yyyy-MM-dd" )       #lowercase m is minutes 
        self.Editlabel3.setCalendarPopup( True )

        self.buttonOK = QPushButton( "OK" )

        controlsLayout.addWidget(QLabel(""),0,0,1,6)
        self.message = QLabel( "The train information has not been queried yet!" )
        controlsLayout.addWidget(self.message,0,7,1,4)

        controlsLayout.addWidget(self.label1,0,11,1,1)
        controlsLayout.addWidget(self.Editlabel1,0,12,1,2)
        controlsLayout.addWidget(QLabel(" "),0,14,1,1)

        controlsLayout.addWidget(self.label2,0,15,1,1)
        controlsLayout.addWidget(self.Editlabel2,0,16,1,2)
        controlsLayout.addWidget(QLabel(" "),0,18,1,1)

        controlsLayout.addWidget(self.label3,0,19,1,1)
        controlsLayout.addWidget(self.Editlabel3,0,20,1,2)
        controlsLayout.addWidget(QLabel(" "),0,22,1,1)

        controlsLayout.addWidget(self.buttonOK,0,23,1,1)
        controlsLayout.addWidget(QLabel(" "),0,25,1,8)

        #The second part, display the queried train information 
        horizontalHeader = [ "Train" , "Station" , "Time" , "Duration" , "Business Seat" , "First Class Seat" , "Second Class Seat" , "Advanced Soft Sleeper" " , "soft sleeper" , "movement sleeper" , "hard sleeper" , "soft seat" , "hard seat" , "no seat" , "other" ]
        self.table = QTableWidget()
        self.table.setColumnCount(15)
        self.table.setRowCount( 0 )        # initialized to 0 rows
        self.table.setHorizontalHeaderLabels(horizontalHeader)
        self.table.setEditTriggers(QTableWidget.NoEditTriggers)      #Cannot edit 
        self.table.setSelectionBehavior(QTableWidget.SelectRows) #Select     the entire row
        self.table.setSelectionMode(QTableWidget.SingleSelection)
        for index in range(self.table.columnCount()):
            headItem = self.table.horizontalHeaderItem(index)
            headItem.setFont(QFont( "song" , 12 , QFont.Bold))
            headItem.setForeground(QBrush(Qt.gray))
            headItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
        #self.table.setFrameShape(QFrame.HLine)#Set the style 
        #self.table.setShowGrid(False) #Cancel the grid line 
        #self.table.verticalHeader().setVisible(False) #Hide the vertical header 
        #row_count = self.table.rowCount() 
        #self.table.setColumnWidth(0,200)
        mainLayout = QHBoxLayout()
        mainLayout.addWidget(self.table)
        layout = QVBoxLayout()
        layout.addLayout(controlsLayout)
        layout.addLayout(mainLayout)
        self.setLayout(layout)
        self.buttonOK.clicked.connect(self.showMessage)
        self.showMaximized()

    def  closeEvent (self, event) : #When         closing the pop-up prompt 
        reply = QMessageBox.question(self, 'warning' , 'The query record will not be saved,\nConfirm to exit?' ,QMessageBox.Yes,QMessageBox.No)
         if reply == QMessageBox.Yes:
            event.accept()
        else:
            event.ignore()

    def  showMessage (self) : #Show       query information 
        stations_fz = dict(map( lambda t:(t[ 1 ],t[ 0 ]), stations.items()))      #Reverse dictionary 
        from_s = self.Editlabel1.text( )    #Get the text box content
        to_s = self.Editlabel2.text()
        if (from_s in stations.keys()) and (to_s in stations.keys()):
            f = stations[from_s]      # Convert to abbreviations corresponding to stations through a dictionary 
            t = stations[to_s]        # Convert to abbreviations corresponding to stations through a dictionary
            date = self.Editlabel3.text()
            d = str(date)
            # print(d) 
            # print('Querying' + from_s + 'to' + to_s + 'train...') 
            url = 'https://kyfw.12306.cn/otn/leftTicket/queryO?leftTicketDTO. train_date=' + d + '&leftTicketDTO.from_station=' + f + '&leftTicketDTO.to_station=' + t + '&purpose_codes=ADULT' 
            # print(url) 
            warnings.filterwarnings( "ignore" )   ​​# This website has security warnings , this code can ignore the warning 
            r = requests.get(url, verify= False )
            raw_trains = r.json()[ 'data' ][ 'result' ]      # Get train information 
            # print(raw_trains) 
            num = len(raw_trains)        # Get the number of trains 
            # print('A total of %d train information was queried'% num) 
            self.message.setText( "A total of %d train information was queried" %num)
             if raw_trains == []:
                QMessageBox.warning(self, "Prompt" , "There is currently no information about the number of trains queried!" )
            i=0
            self.table.setRowCount(num)
            self.table.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) #Close       the horizontal scroll bar 
            for raw_train in raw_trains:
                 # After splitting, a list is obtained 
                data_list = raw_train.split( "|" )
                 # print(data_list) 
                tra_no = data_list[ 2 ]      #train_no 
                from_s_no = data_list[ 16 ]    #from_station_no 
                to_s_no = data_list[ 17 ]      #to_station_no 
                seat_type = data_list[ 35 ]        #seat_types
                tra_date = d             #train_date 
                checi = data_list[ 3 ]      # Train times 
                cfd = stations_fz[data_list[ 6 ]]       # Departure point, converted by dictionary 
                mdd = stations_fz[data_list[ 7 ]]       # Destination 
                fctime = data_list[ 8 ]     # Departure time 
                ddtime = data_list[ 9 ]     # Arrival time 
                lishi = data_list[ 10 ]     # Duration 
                shangwuzuo = data_list[ 32 ] or  "--"     # Business class/Prime class seat
                yidengzuo = data_list[ 31 ] or  "--"      # First class 
                erdengzuo = data_list[ 30 ] or  "--"      # Second class 
                gjruanwo = data_list[ 21 ] or  "--"       # Superior soft sleeper 
                ruanwo = data_list[ 23 ] or  "--"         # Soft sleeper 
                dongwo = data_list[ 33 ] or  "--"         # Dynamic sleeper 
                ruanzuo = data_list[24] or  "--"        # Soft seat 
                yingzuo = data_list[ 29 ] or  "--"        # Hard seat 
                wuzuo = data_list[ 26 ] or  "--"          # No seat 
                others = data_list[ 22 ] or  "--"         # Other

                price_url = "https://kyfw.12306.cn/otn/leftTicket/queryTicketPrice?train_no="+tra_no+"&from_station_no="+from_s_no+"&to_station_no="+to_s_no+"&seat_types="+seat_type+"&train_date="+tra_date
                r1 = requests.get(price_url, verify= False )
                 # print(price_url) 
                raw_prices = r1.json()[ 'data' ]   # Get train information 
                if  'A1'  in raw_prices.keys():            #A1:hard seat 
                    pr_yz = raw_prices[ 'A1' ]
                 else :
                    pr_yz = ''
                    pr_rz = raw_prices['A2']
                else:
                    pr_rz = ''
                    pr_yw = raw_prices['A3']
                else:
                    pr_yw = ''
                    pr_rw = raw_prices['A4']
                else:
                    pr_rw = '' 
                if  'A6'  in raw_prices.keys():            # A6: Advanced soft sleeper 
                    pr_gjrw = raw_prices[ 'A6' ]
                 else :
                    pr_gjrw = '' 
                if  'A9'  in raw_prices.keys():            # A9: business seat, state class seat 
                    pr_swz = raw_prices[ 'A9' ]
                 else :
                    pr_swz = ''
                    pr_wz = raw_prices['WZ']
                else:
                    pr_wz = ''
                    pr_ydz = raw_prices['M']
                else:
                    pr_ydz = ''
                    pr_edz = raw_prices['O']
                else:
                    pr_edz = ''
                    pr_dw = raw_prices['F']
                else:
                    pr_dw = '' 
                # print(pr_yz,pr_rz,pr_yw,pr_rw,pr_gjrw,pr_swz,pr_wz,pr_ydz,pr_edz,pr_dw)
                NewItem=QTableWidgetItem(checi)
                NewItem.setForeground(QColor(Qt.red))
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter) #vertically   center 
                self.table.setItem(i, 0 ,NewItem)

                NewItem=QTableWidgetItem(cfd +'\n-\n'+mdd)
                NewItem.setFont(QFont( "song" , 9 , QFont.Bold))
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,1,NewItem)

                NewItem=QTableWidgetItem(fctime+'\n-\n'+ddtime)
                NewItem.setFont(QFont( "song" , 9 , QFont.Bold))
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,2,NewItem)

                NewItem=QTableWidgetItem(list)
                NewItem.setFont(QFont( "song" , 9 , QFont.Bold))
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,3,NewItem)

                NewItem=QTableWidgetItem(shangwuzuo+ '\n' +pr_swz)
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,4,NewItem)

                NewItem=QTableWidgetItem(yidengzuo+'\n'+ pr_ydz)
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,5,NewItem)

                NewItem=QTableWidgetItem(erdengzuo+ '\n' + pr_edz)
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,6,NewItem)

                NewItem=QTableWidgetItem(gjruanwo+'\n'+ pr_gjrw)
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,7,NewItem)

                NewItem=QTableWidgetItem(ruanwo+'\n'+ pr_rw)
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,8,NewItem)

                NewItem=QTableWidgetItem(dongwo+ '\n' + pr_dw)
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,9,NewItem)

                NewItem=QTableWidgetItem(yingwo+'\n'+ pr_yw)
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,10,NewItem)

                NewItem=QTableWidgetItem(ruanzuo+'\n'+ pr_rz)
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,11,NewItem)

                NewItem=QTableWidgetItem(yingzuo+'\n'+ pr_yz)
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,12,NewItem)

                NewItem=QTableWidgetItem(wuzuo+'\n'+ pr_wz)
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,13,NewItem)

                NewItem=QTableWidgetItem(others+'\n'+'')
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,14,NewItem)

                self.table.setRowHeight(i, 60 )       #Set row height

                i=i+ 1 
            #self.table.setSpan(0, 8, 2, 1) #merge cells 
        else :
             if from_s not  in stations.keys():
                 # print('Please enter the correct starting point') 
                QMessageBox.warning (self, "hint" , "please enter the correct starting point!" )
             if to_s not  in stations.keys():
                 # print('please enter the correct destination') 
                QMessageBox.warning(self, "hint" , " Please enter the correct destination!" )
 if __name__ == '__main__' :
    app = QApplication(sys.argv)
    table = TableSheet()
    table.show()
    sys.exit(app.exec_())

'''
Train ticket inquiry system
'''
__author__ = 'Scorpio'
import sys
from PyQt5.QtCore import Qt,QDateTime
from PyQt5.QtWidgets import QWidget,QMessageBox,QApplication,QLabel,QTableWidget,QLineEdit,QHBoxLayout,QGridLayout,QVBoxLayout,QPushButton,QTableWidgetItem,QFrame,QDateTimeEdit
from PyQt5.QtGui import QFont,QColor,QBrush
from get_stations import stations
import warnings
import requests
class TableSheet(QWidget):
    def __init__(self):
        super().__init__()
        self.initUi()

    def  initUi (self) : 
        #self.setWindowFlags(Qt.WindowCloseButtonHint && Qt.WindowMinimizeButtonHint) 
        #self.setWindowFlags(Qt.WindowMinimizeButtonHint) 
        self.setWindowTitle( 'Train ticket query system' )
         #self.setGeometry(40,80,1500, 720) #The 
        first part, enter the origin, destination and date 
        controlsLayout = QGridLayout()       #Grid layout 
        self.label1 = QLabel( "Departure:" )
        self.Editlabel1 = QLineEdit()
        self.label2 = QLabel( "Destination:" )
        self.Editlabel2 = QLineEdit()
        self.label3 = QLabel( "Ride date: " )

        self.Editlabel3 = QDateTimeEdit()
        now = QDateTime.currentDateTime()
        #print(now)
        self.Editlabel3.setDateTime(now)
        self.Editlabel3.setDisplayFormat( "yyyy-MM-dd" )       #lowercase m is minutes 
        self.Editlabel3.setCalendarPopup( True )

        self.buttonOK = QPushButton( "OK" )

        controlsLayout.addWidget(QLabel(""),0,0,1,6)
        self.message = QLabel( "The train information has not been queried yet!" )
        controlsLayout.addWidget(self.message,0,7,1,4)

        controlsLayout.addWidget(self.label1,0,11,1,1)
        controlsLayout.addWidget(self.Editlabel1,0,12,1,2)
        controlsLayout.addWidget(QLabel(" "),0,14,1,1)

        controlsLayout.addWidget(self.label2,0,15,1,1)
        controlsLayout.addWidget(self.Editlabel2,0,16,1,2)
        controlsLayout.addWidget(QLabel(" "),0,18,1,1)

        controlsLayout.addWidget(self.label3,0,19,1,1)
        controlsLayout.addWidget(self.Editlabel3,0,20,1,2)
        controlsLayout.addWidget(QLabel(" "),0,22,1,1)

        controlsLayout.addWidget(self.buttonOK,0,23,1,1)
        controlsLayout.addWidget(QLabel(" "),0,25,1,8)

        #The second part, display the queried train information 
        horizontalHeader = [ "Train" , "Station" , "Time" , "Duration" , "Business Seat" , "First Class Seat" , "Second Class Seat" , "Advanced Soft Sleeper" " , "soft sleeper" , "movement sleeper" , "hard sleeper" , "soft seat" , "hard seat" , "no seat" , "other" ]
        self.table = QTableWidget()
        self.table.setColumnCount(15)
        self.table.setRowCount( 0 )        # initialized to 0 rows
        self.table.setHorizontalHeaderLabels(horizontalHeader)
        self.table.setEditTriggers(QTableWidget.NoEditTriggers)      #Cannot edit 
        self.table.setSelectionBehavior(QTableWidget.SelectRows) #Select     the entire row
        self.table.setSelectionMode(QTableWidget.SingleSelection)
        for index in range(self.table.columnCount()):
            headItem = self.table.horizontalHeaderItem(index)
            headItem.setFont(QFont( "song" , 12 , QFont.Bold))
            headItem.setForeground(QBrush(Qt.gray))
            headItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
        #self.table.setFrameShape(QFrame.HLine)#Set the style 
        #self.table.setShowGrid(False) #Cancel the grid line 
        #self.table.verticalHeader().setVisible(False) #Hide the vertical header 
        #row_count = self.table.rowCount() 
        #self.table.setColumnWidth(0,200)
        mainLayout = QHBoxLayout()
        mainLayout.addWidget(self.table)
        layout = QVBoxLayout()
        layout.addLayout(controlsLayout)
        layout.addLayout(mainLayout)
        self.setLayout(layout)
        self.buttonOK.clicked.connect(self.showMessage)
        self.showMaximized()

    def  closeEvent (self, event) : #When         closing the pop-up prompt 
        reply = QMessageBox.question(self, 'warning' , 'The query record will not be saved,\nConfirm to exit?' ,QMessageBox.Yes,QMessageBox.No)
         if reply == QMessageBox.Yes:
            event.accept()
        else:
            event.ignore()

    def  showMessage (self) : #Show       query information 
        stations_fz = dict(map( lambda t:(t[ 1 ],t[ 0 ]), stations.items()))      #Reverse dictionary 
        from_s = self.Editlabel1.text( )    #Get the text box content
        to_s = self.Editlabel2.text()
        if (from_s in stations.keys()) and (to_s in stations.keys()):
            f = stations[from_s]      # Convert to abbreviations corresponding to stations through a dictionary 
            t = stations[to_s]        # Convert to abbreviations corresponding to stations through a dictionary
            date = self.Editlabel3.text()
            d = str(date)
            # print(d) 
            # print('Querying' + from_s + 'to' + to_s + 'train...') 
            url = 'https://kyfw.12306.cn/otn/leftTicket/queryO?leftTicketDTO. train_date=' + d + '&leftTicketDTO.from_station=' + f + '&leftTicketDTO.to_station=' + t + '&purpose_codes=ADULT' 
            # print(url) 
            warnings.filterwarnings( "ignore" )   ​​# This website has security warnings , this code can ignore the warning 
            r = requests.get(url, verify= False )
            raw_trains = r.json()[ 'data' ][ 'result' ]      # Get train information 
            # print(raw_trains) 
            num = len(raw_trains)        # Get the number of trains 
            # print('A total of %d train information was queried'% num) 
            self.message.setText( "A total of %d train information was queried" %num)
             if raw_trains == []:
                QMessageBox.warning(self, "Prompt" , "There is currently no information about the number of trains queried!" )
            i=0
            self.table.setRowCount(num)
            self.table.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) #Close       the horizontal scroll bar 
            for raw_train in raw_trains:
                 # After splitting, a list is obtained 
                data_list = raw_train.split( "|" )
                 # print(data_list) 
                tra_no = data_list[ 2 ]      #train_no 
                from_s_no = data_list[ 16 ]    #from_station_no 
                to_s_no = data_list[ 17 ]      #to_station_no 
                seat_type = data_list[ 35 ]        #seat_types
                tra_date = d             #train_date 
                checi = data_list[ 3 ]      # Train times 
                cfd = stations_fz[data_list[ 6 ]]       # Departure point, converted by dictionary 
                mdd = stations_fz[data_list[ 7 ]]       # Destination 
                fctime = data_list[ 8 ]     # Departure time 
                ddtime = data_list[ 9 ]     # Arrival time 
                lishi = data_list[ 10 ]     # Duration 
                shangwuzuo = data_list[ 32 ] or  "--"     # Business class/Prime class seat
                yidengzuo = data_list[ 31 ] or  "--"      # First class 
                erdengzuo = data_list[ 30 ] or  "--"      # Second class 
                gjruanwo = data_list[ 21 ] or  "--"       # Superior soft sleeper 
                ruanwo = data_list[ 23 ] or  "--"         # Soft sleeper 
                dongwo = data_list[ 33 ] or  "--"         # Dynamic sleeper 
                ruanzuo = data_list[24] or  "--"        # Soft seat 
                yingzuo = data_list[ 29 ] or  "--"        # Hard seat 
                wuzuo = data_list[ 26 ] or  "--"          # No seat 
                others = data_list[ 22 ] or  "--"         # Other

                price_url = "https://kyfw.12306.cn/otn/leftTicket/queryTicketPrice?train_no="+tra_no+"&from_station_no="+from_s_no+"&to_station_no="+to_s_no+"&seat_types="+seat_type+"&train_date="+tra_date
                r1 = requests.get(price_url, verify= False )
                 # print(price_url) 
                raw_prices = r1.json()[ 'data' ]   # Get train information 
                if  'A1'  in raw_prices.keys():            #A1:hard seat 
                    pr_yz = raw_prices[ 'A1' ]
                 else :
                    pr_yz = ''
                    pr_rz = raw_prices['A2']
                else:
                    pr_rz = ''
                    pr_yw = raw_prices['A3']
                else:
                    pr_yw = ''
                    pr_rw = raw_prices['A4']
                else:
                    pr_rw = '' 
                if  'A6'  in raw_prices.keys():            # A6: Advanced soft sleeper 
                    pr_gjrw = raw_prices[ 'A6' ]
                 else :
                    pr_gjrw = '' 
                if  'A9'  in raw_prices.keys():            # A9: business seat, state class seat 
                    pr_swz = raw_prices[ 'A9' ]
                 else :
                    pr_swz = ''
                    pr_wz = raw_prices['WZ']
                else:
                    pr_wz = ''
                    pr_ydz = raw_prices['M']
                else:
                    pr_ydz = ''
                    pr_edz = raw_prices['O']
                else:
                    pr_edz = ''
                    pr_dw = raw_prices['F']
                else:
                    pr_dw = '' 
                # print(pr_yz,pr_rz,pr_yw,pr_rw,pr_gjrw,pr_swz,pr_wz,pr_ydz,pr_edz,pr_dw)
                NewItem=QTableWidgetItem(checi)
                NewItem.setForeground(QColor(Qt.red))
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter) #vertically   center 
                self.table.setItem(i, 0 ,NewItem)

                NewItem=QTableWidgetItem(cfd +'\n-\n'+mdd)
                NewItem.setFont(QFont( "song" , 9 , QFont.Bold))
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,1,NewItem)

                NewItem=QTableWidgetItem(fctime+'\n-\n'+ddtime)
                NewItem.setFont(QFont( "song" , 9 , QFont.Bold))
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,2,NewItem)

                NewItem=QTableWidgetItem(list)
                NewItem.setFont(QFont( "song" , 9 , QFont.Bold))
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,3,NewItem)

                NewItem=QTableWidgetItem(shangwuzuo+ '\n' +pr_swz)
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,4,NewItem)

                NewItem=QTableWidgetItem(yidengzuo+'\n'+ pr_ydz)
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,5,NewItem)

                NewItem=QTableWidgetItem(erdengzuo+ '\n' + pr_edz)
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,6,NewItem)

                NewItem=QTableWidgetItem(gjruanwo+'\n'+ pr_gjrw)
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,7,NewItem)

                NewItem=QTableWidgetItem(ruanwo+'\n'+ pr_rw)
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,8,NewItem)

                NewItem=QTableWidgetItem(dongwo+ '\n' + pr_dw)
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,9,NewItem)

                NewItem=QTableWidgetItem(yingwo+'\n'+ pr_yw)
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,10,NewItem)

                NewItem=QTableWidgetItem(ruanzuo+'\n'+ pr_rz)
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,11,NewItem)

                NewItem=QTableWidgetItem(yingzuo+'\n'+ pr_yz)
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,12,NewItem)

                NewItem=QTableWidgetItem(wuzuo+'\n'+ pr_wz)
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,13,NewItem)

                NewItem=QTableWidgetItem(others+'\n'+'')
                NewItem.setTextAlignment(Qt.AlignCenter | Qt.AlignVCenter)
                self.table.setItem(i,14,NewItem)

                self.table.setRowHeight(i, 60 )       #Set row height

                i=i+ 1 
            #self.table.setSpan(0, 8, 2, 1) #merge cells 
        else :
             if from_s not  in stations.keys():
                 # print('Please enter the correct starting point') 
                QMessageBox.warning (self, "hint" , "please enter the correct starting point!" )
             if to_s not  in stations.keys():
                 # print('please enter the correct destination') 
                QMessageBox.warning(self, "hint" , " Please enter the correct destination!" )
 if __name__ == '__main__' :
    app = QApplication(sys.argv)
    table = TableSheet()
    table.show()
    sys.exit(app.exec_())


1) Interface effect

2) Date and time

3) Record deletion

More hidden effects are waiting for you to experience~

Summarize

Okay! The article is officially over here! Finally, I wish everyone a happy holiday (festival) in the future, a happy journey, and all

Get your wish~ Old rules source material or something👇

🎯Complete free source code collection: find me! At the end of the article, the public can get it by themselves, and I can too!

🔨Recommend previous articles——

Project 1.0 Flying Snow applet

Python applet: you see? This thousand-year-old snow scene – simply “beautiful to foul” [full screen of snowflakes flying]

Item 1.1 Resignation applet

[[With Python version teaching] “The wonderful reasons for resignation used in those years” Hahaha, I laughed out loud after reading it.]

Project 1.3 Video Player

I used the Python-specific ad-free video player that everyone said, and I want to call crazy for it.

Item 3.2 Automatic wallpaper changer

[Advanced Python Skills] Super cool, the computer automatically changes wallpapers every day, this artifact is suitable for you.

Project 4.7 Movie booking system

[Python ticketing system] This is the correct way to choose a seat for watching a movie. It turns out that we are all fooled~ (seat selection, one-click ticket purchase)

🎄Article Summary——

Project 1.0  Python—2021 | Summary of existing articles | Continuously updated, just read this article

(More content + source code are summarized in the article!! Welcome to read~)

Leave a Comment

Your email address will not be published. Required fields are marked *