1. 程式人生 > 其它 >Jenkins 整合 CI SpringBoot 與 Vue 並觸發 Git 提交自動構建

Jenkins 整合 CI SpringBoot 與 Vue 並觸發 Git 提交自動構建

1、Treeview的基本屬性

  • 常用引數意義

①master=win, # 父容器

②height=10, # 表格顯示的行數,height行

③columns=columns, # 顯示的列

④show='headings', # 隱藏首列

⑤heading() # 定義表頭

⑥column()#定義列

⑦anchor='w'#對齊方式,可選n, ne, e, se, s, sw, w, nw, center

⑧command=lambda: print('學號')#點選表頭執行的回撥函式

⑨minwidth=100#表格的最小列寬

# -*- encoding=utf-8 -*-
import tkinter
from tkinter import *
from tkinter import ttk

if __name__ == '__main__':
    pass
    win = tkinter.Tk()  # 視窗
    win.title('南風丶輕語')  # 標題
    screenwidth = win.winfo_screenwidth()  # 螢幕寬度
    screenheight = win.winfo_screenheight()  # 螢幕高度
    width = 1000
    height = 500
    x = int((screenwidth - width) / 2)
    y = int((screenheight - height) / 2)
    win.geometry('{}x{}+{}+{}'.format(width, height, x, y))  # 大小以及位置

    columns = ['學號', '姓名', '性別', '出生年月', '籍貫', '班級']
    table = ttk.Treeview(
            master=win,  # 父容器
            height=10,  # 表格顯示的行數,height行
            columns=columns,  # 顯示的列
            show='headings',  # 隱藏首列
            )

    table.heading(column='學號', text='學號', anchor='w',
                  command=lambda: print('學號'))  # 定義表頭
    table.heading('姓名', text='姓名', )  # 定義表頭
    table.heading('性別', text='性別', )  # 定義表頭
    table.heading('出生年月', text='出生年月', )  # 定義表頭
    table.heading('籍貫', text='籍貫', )  # 定義表頭
    table.heading('班級', text='班級', )  # 定義表頭

    table.column('學號', width=100, minwidth=100, anchor=S, )  # 定義列
    table.column('姓名', width=150, minwidth=100, anchor=S)  # 定義列
    table.column('性別', width=50, minwidth=50, anchor=S)  # 定義列
    table.column('出生年月', width=150, minwidth=100, anchor=S)  # 定義列
    table.column('籍貫', width=150, minwidth=100, anchor=S)  # 定義列
    table.column('班級', width=150, minwidth=100, anchor=S)  # 定義列
    table.pack(pady=20)

    win.mainloop()

執行

2、插入資料到表格中

  • 常用引數意義

①table.insert('', END, values=data) # 新增資料到末尾

# -*- encoding=utf-8 -*-

import tkinter
from tkinter import *
from tkinter import messagebox
from tkinter import ttk


def insert():
    # 插入資料
    info = [
        ['1001', '李華', '男', '2014-01-25', '廣東', '計算5班', ],
        ['1002', '小米', '男', '2015-11-08', '深圳', '計算5班', ],
        ['1003', '劉亮', '男', '2015-09-12', '福建', '計算5班', ],
        ['1004', '白鴿', '女', '2016-04-01', '湖南', '計算5班', ],
        ]
    for index, data in enumerate(info):
        table.insert('', END, values=data)  # 新增資料到末尾


if __name__ == '__main__':
    pass
    win = tkinter.Tk()  # 視窗
    win.title('南風丶輕語')  # 標題
    screenwidth = win.winfo_screenwidth()  # 螢幕寬度
    screenheight = win.winfo_screenheight()  # 螢幕高度
    width = 1000
    height = 500
    x = int((screenwidth - width) / 2)
    y = int((screenheight - height) / 2)
    win.geometry('{}x{}+{}+{}'.format(width, height, x, y))  # 大小以及位置

    tabel_frame = tkinter.Frame(win)
    tabel_frame.pack()

    xscroll = Scrollbar(tabel_frame, orient=HORIZONTAL)
    yscroll = Scrollbar(tabel_frame, orient=VERTICAL)

    columns = ['學號', '姓名', '性別', '出生年月', '籍貫', '班級']
    table = ttk.Treeview(
            master=tabel_frame,  # 父容器
            height=10,  # 表格顯示的行數,height行
            columns=columns,  # 顯示的列
            show='headings',  # 隱藏首列
            xscrollcommand=xscroll.set,  # x軸滾動條
            yscrollcommand=yscroll.set,  # y軸滾動條
            )
    for column in columns:
        table.heading(column=column, text=column, anchor=CENTER,
                      command=lambda name=column:
                      messagebox.showinfo('', '{}描述資訊~~~'.format(name)))  # 定義表頭
        table.column(column=column, width=100, minwidth=100, anchor=CENTER, )  # 定義列
    xscroll.config(command=table.xview)
    xscroll.pack(side=BOTTOM, fill=X)
    yscroll.config(command=table.yview)
    yscroll.pack(side=RIGHT, fill=Y)
    table.pack(fill=BOTH, expand=True)

    insert()
    insert()
    insert()
    insert()
    btn_frame = Frame()
    btn_frame.pack()
    Button(btn_frame, text='新增', bg='yellow', width=20, command=insert).pack()
    win.mainloop()

3、刪除表格中的資料

  • 常用引數意義

①get_children()#獲取所有物件

②table.delete()#刪除物件

# -*- encoding=utf-8 -*-
import tkinter
from tkinter import *
from tkinter import ttk


def insert():
    # 插入資料
    info = [
        ['1001', '李華', '男', '2014-01-25', '廣東', '計算5班', ],
        ['1002', '小米', '男', '2015-11-08', '深圳', '計算5班', ],
        ['1003', '劉亮', '男', '2015-09-12', '福建', '計算5班', ],
        ['1004', '白鴿', '女', '2016-04-01', '湖南', '計算5班', ],
        ]
    for index, data in enumerate(info):
        table.insert('', END, values=data)  # 新增資料到末尾


def delete():
    obj = table.get_children()  # 獲取所有物件
    for o in obj:
        table.delete(o)  # 刪除物件


if __name__ == '__main__':
    pass
    win = tkinter.Tk()  # 視窗
    win.title('南風丶輕語')  # 標題
    screenwidth = win.winfo_screenwidth()  # 螢幕寬度
    screenheight = win.winfo_screenheight()  # 螢幕高度
    width = 1000
    height = 500
    x = int((screenwidth - width) / 2)
    y = int((screenheight - height) / 2)
    win.geometry('{}x{}+{}+{}'.format(width, height, x, y))  # 大小以及位置

    columns = ['學號', '姓名', '性別', '出生年月', '籍貫', '班級']
    table = ttk.Treeview(
            master=win,  # 父容器
            height=10,  # 表格顯示的行數,height行
            columns=columns,  # 顯示的列
            show='headings',  # 隱藏首列
            )

    table.heading(column='學號', text='學號', anchor='w',
                  command=lambda: print('學號'))  # 定義表頭
    table.heading('姓名', text='姓名', )  # 定義表頭
    table.heading('性別', text='性別', )  # 定義表頭
    table.heading('出生年月', text='出生年月', )  # 定義表頭
    table.heading('籍貫', text='籍貫', )  # 定義表頭
    table.heading('班級', text='班級', )  # 定義表頭

    table.column('學號', width=100, minwidth=100, anchor=S, )  # 定義列
    table.column('姓名', width=150, minwidth=100, anchor=S)  # 定義列
    table.column('性別', width=50, minwidth=50, anchor=S)  # 定義列
    table.column('出生年月', width=150, minwidth=100, anchor=S)  # 定義列
    table.column('籍貫', width=150, minwidth=100, anchor=S)  # 定義列
    table.column('班級', width=150, minwidth=100, anchor=S)  # 定義列
    table.pack(pady=20)

    insert()
    f = Frame()
    f.pack()
    Button(f, text='新增', bg='yellow', width=20, command=insert).pack(side=LEFT)
    Button(f, text='刪除', bg='pink', width=20, command=delete).pack(side=LEFT)
    win.mainloop()

4、新增滾動條

  • 常用引數意義

①xscroll = Scrollbar(tabel_frame, orient=HORIZONTAL)#水平滾動條

②yscroll = Scrollbar(tabel_frame, orient=VERTICAL)#垂直滾動條

③xscrollcommand=xscroll.set, # table繫結x軸滾動條事件

④yscrollcommand=yscroll.set, # table繫結y軸滾動條事件

⑤xscroll.config(command=table.xview)#水平滾動條繫結table的x軸事件

⑥xscroll.pack(side=BOTTOM, fill=X)#放置水平滾動條,放在最下面

⑦yscroll.config(command=table.yview)#垂直滾動條繫結table的y軸事件

⑧yscroll.pack(side=RIGHT, fill=Y)#垂直滾動條,放置在最右邊

⑨table.pack(fill=BOTH, expand=True)#放置table,必須寫在放置水平和垂直滾動條之後

# -*- encoding=utf-8 -*-

import tkinter
from tkinter import *
from tkinter import messagebox
from tkinter import ttk


def insert():
    # 插入資料
    info = [
        ['1001', '李華', '男', '2014-01-25', '廣東', '計算5班', ],
        ['1002', '小米', '男', '2015-11-08', '深圳', '計算5班', ],
        ['1003', '劉亮', '男', '2015-09-12', '福建', '計算5班', ],
        ['1004', '白鴿', '女', '2016-04-01', '湖南', '計算5班', ],
        ]
    for index, data in enumerate(info):
        table.insert('', END, values=data)  # 新增資料到末尾


if __name__ == '__main__':
    pass
    win = tkinter.Tk()  # 視窗
    win.title('南風丶輕語')  # 標題
    screenwidth = win.winfo_screenwidth()  # 螢幕寬度
    screenheight = win.winfo_screenheight()  # 螢幕高度
    width = 1000
    height = 500
    x = int((screenwidth - width) / 2)
    y = int((screenheight - height) / 2)
    win.geometry('{}x{}+{}+{}'.format(width, height, x, y))  # 大小以及位置

    tabel_frame = tkinter.Frame(win)
    tabel_frame.pack()

    xscroll = Scrollbar(tabel_frame, orient=HORIZONTAL)
    yscroll = Scrollbar(tabel_frame, orient=VERTICAL)

    columns = ['學號', '姓名', '性別', '出生年月', '籍貫', '班級']
    table = ttk.Treeview(
            master=tabel_frame,  # 父容器
            height=10,  # 表格顯示的行數,height行
            columns=columns,  # 顯示的列
            show='headings',  # 隱藏首列
            xscrollcommand=xscroll.set,  # x軸滾動條
            yscrollcommand=yscroll.set,  # y軸滾動條
            )
    for column in columns:
        table.heading(column=column, text=column, anchor=CENTER,
                      command=lambda name=column:
                      messagebox.showinfo('', '{}描述資訊~~~'.format(name)))  # 定義表頭
        table.column(column=column, width=100, minwidth=100, anchor=CENTER, )  # 定義列
    xscroll.config(command=table.xview)
    xscroll.pack(side=BOTTOM, fill=X)
    yscroll.config(command=table.yview)
    yscroll.pack(side=RIGHT, fill=Y)
    table.pack(fill=BOTH, expand=True)

    insert()
    insert()
    insert()
    insert()
    btn_frame = Frame()
    btn_frame.pack()
    Button(btn_frame, text='新增', bg='yellow', width=20, command=insert).pack()
    win.mainloop()
  • 易錯點

①command=lambda name=column:messagebox.showinfo('', '{}描述資訊~~~'.format(name)) 正確繫結事件

點選表頭後,顯示對應表頭的描述資訊

command=lambda :messagebox.showinfo('', '{}描述資訊~~~'.format(column)) 錯誤繫結事件

點選表頭後每次顯示的都是描述班級資訊(列表最後一個元素)

區別在於正確寫法給定了形參,每個形參使用for迴圈給的區域性變數column的值,每次都是不一樣的,而錯誤寫法給定的是for迴圈中的區域性變數column,for迴圈結束後,區域性變數column就是最後一個列表的值,因此輸出都是列表最後一個值