0

I have a problem with scrolling the horizontal bar. When I add another column is the whole I'm leaving the window in which I display it. Is it possible to set the size of the treeview permanently and scroll the columns with the horizontal bar? The screen may be too small at present. To display the data content.

Here is my source

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)
MarcinB
  • 17
  • 9
  • Try this approach [attach a horizontal and vertical scrollbar to a treeview](https://stackoverflow.com/a/33376178/7414759) – stovfl Feb 21 '19 at 17:49
  • I would like to reduce the window in which I display the data, but I can not do it and the whole table is very large. Thanks to the horizontal scroll bar, you could reduce the main window and look aesthetically. Unfortunately it does not work :( – MarcinB Feb 21 '19 at 18:17
  • And when I add another column, the table automatically expands to me. And I can not make a larger main window because it will not fit on the screen. Please help me how to do it with the horizontal scroll bar. – MarcinB Feb 21 '19 at 18:38
  • *"possible to set the size of the treeview permanently"*: **No**. Use this pattern [Adding a scrollbar](https://stackoverflow.com/a/3092341/7414759) add a `orient='horizontal'` `Scrollbar`, your `Treeview` goes into `def populate(self):` – stovfl Feb 22 '19 at 09:31
  • Thank you for help @stovfl, it works great. – MarcinB Feb 23 '19 at 08:53
  • hey @stovfl I am having issues with horizontal scrollbars as well and I think I am following the approach you shown recommended in the link about. can you check my code and advise what seems to be the problem there? thank you. here is the link https://stackoverflow.com/questions/62248510/tkinter-how-do-i-add-a-horizontal-scroll-bar-to-my-treeview – user13412850 Jun 07 '20 at 22:29

0 Answers0