水平滚动条无法正常工作,TreeView-python

时间:2019-02-21 15:35:19

标签: python python-2.7 treeview ttk

滚动水平栏时出现问题。当我添加另一列是整体 我要离开显示它的窗口。是否可以永久设置树视图的大小并使用水平条滚动列? 屏幕目前可能太小。显示数据内容。

这是我的来源

def wczytaj_dane(page):
    ok = Toplevel()
    width_of_window = 1030
    height_of_window = 570
    screen_width = ok.winfo_screenwidth()
    screen_height = ok.winfo_screenheight()
    x_coordinate = (screen_width/2) - (width_of_window/2)
    y_coordinate = (screen_height/2) - (height_of_window/2)
    ok.geometry("%dx%d+%d+%d" % (width_of_window, height_of_window, x_coordinate, y_coordinate))

    """Polączenie z bazą danych oraz pobieranie danych"""

    connection = pymysql. connect ( host = '192.168.10.100' ,
                                    database = 'tester_produkcja' ,
                                    user = 'marcin' ,
                                    password = 'marcin96' )
    try:
        with connection . cursor () as cursor :
            sql= "SELECT * FROM `Historia` WHERE `Poczernin_kod_Produktu`='DP^8E0E1^0005'"
            cursor.execute ( sql,)
            result_dpcode = cursor.fetchall () #fetchone ()

            """ zamiana krotki(tuple) na liczbę całkowitą"""  
            #result_dp = int(result_dpcode[0])
    finally:
        connection.close()



        tree = ttk.Treeview(ok,height=5)
        tree["columns"]=("one","two","three","four","five","six","seven","eight","nine","ten","ten1","ten2","ten3","ten4","ten5",
                         "ten6","ten7")

        tree.column("#0", width=40)
        tree.column("one", width=100 )
        tree.column("two", width=50)
        tree.column("three", width=220)
        tree.column("four", width=50 )
        tree.column("five", width=50)
        tree.column("six", width=50)
        tree.column("seven", width=50)
        tree.column("eight", width=50)
        tree.column("nine", width=50)
        tree.column("ten", width=50)
        tree.column("ten1", width=50)
        tree.column("ten2", width=70)
        tree.column("ten3", width=70)
        tree.column("ten4", width=125)
        tree.column("ten5", width=120)
        tree.column("ten6", width=100)
        tree.column("ten7", width=100)


        tree.heading("#0", text="Lp.")
        tree.heading("one", text="Godzina/Data")
        tree.heading("two", text="KTM")
        tree.heading("three",text="Nazwa Produktu")
        tree.heading("four",text="Funkcja")
        tree.heading("five",text="PW")
        tree.heading("six", text="VAC")
        tree.heading("seven",text="WATT")
        tree.heading("eight",text="ŁAD")
        tree.heading("nine",text="ROZŁ")
        tree.heading("ten",text="VDC")
        tree.heading("ten1",text="Uwagi")
        tree.heading("ten2",text="Pracownik")
        tree.heading("ten3",text="Inspektor")
        tree.heading("ten4",text="Poprawność Montażu")
        tree.heading("ten5",text="Wygląd zewnętrzny")
        tree.heading("ten6",text="Wygląd zewnętrzny")
        tree.heading("ten7",text="Wygląd zewnętrzny")




        cpt = 0
        for row in result_dpcode: 
            tree.insert('','end', text=str(cpt), values=(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],
                                                         row[9],row[10],row[11],row[12],row[13],row[14],row[15] )) 
            cpt +=1 



        ysb = ttk.Scrollbar (ok, orient = 'vertical', command = tree.yview)
        xsb = ttk.Scrollbar (ok, orient = 'horizontal', command = tree.xview)
        tree.grid(row=0,column=0)
        ysb.grid (row = 0, column = 1, sticky = N+S)
        xsb.grid (row = 1,column = 0, sticky = E+W)
        tree.configure (yscroll = ysb.set)
        tree.configure (xscroll = xsb.set)

0 个答案:

没有答案