0

Having trouble with this horizontal scroll bar... I've pieced this much together but could be completely wrong. The scroll bar is there where I want it to be it's just unusable and wont scroll anywhere. There are about 83 columns and I can only see 15 of them.

import databasefile
import sqlite3
from tkinter import *
from tkinter.ttk import *

conn = sqlite3.connect("test_db.db")
cursor = conn.cursor()
returns = cursor.execute("SELECT * FROM Order_Number ORDER BY id DESC")


variables = [1,2,3,4,5,6,7,8,9,0,11,12,13,14,15,16,17,18,19,20]

class App(Frame):

def __init__(self, parent):
    Frame.__init__(self, parent)
    self.CreateUI()
    self.grid(sticky = (N,S,W,E))
    parent.grid_rowconfigure(1, weight = 1)
    parent.grid_columnconfigure(1, weight = 1)
    parent.wm_title("Database")
    parent.maxsize(width=1200,height=600)
    parent.resizable(width=0,height=0)

def CreateUI(self):
    tv = Treeview(self)
    tv['columns'] = variables

    # Scroll Bar section
    vsb = Scrollbar(root,orient="horizontal",command=tv.xview)
    tv.configure(xscrollcommand=vsb.set)
    vsb.place(x=0,y=210,height=20, width=1200)


    tv.column("#0", anchor="w",width=25)
    for item in variables:
        tv.heading(str(item),text=str(item))
        tv.column(str(item),anchor='center',width=75)

    tv.grid(sticky = (N,S,W,E))

    self.grid_rowconfigure(index=1, weight = 1)
    self.grid_columnconfigure(index=1, weight = 1)
    for row in returns:
        tv.insert('','end',values=(row))





root = Tk()

App(root)

root.mainloop()
letto4135
  • 23
  • 8
  • Please provide your imports and how you are calling the class. Also we do not know what your `variables` or `returns` are so we cannot really test your code. Please review [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – Mike - SMT May 24 '18 at 21:04
  • I agree with @Mike-SMT, we need a working prototype. On inspection though, I would grid the scrollbar in the same widget with the treeview, because as your application grows, unexpected things will happen to the layout. – Ron Norris May 24 '18 at 22:07
  • Updated it with the whole code, removed the variables because reasons. But left a list of numbers for columns instead. @Mike-SMT – letto4135 May 25 '18 at 19:09
  • First you need to change how you are importing tkinter methods. `ttk` is overriding stuff from tkinter. Instead use these imports: `import tkinter as tk` and `from tkinter import ttk` This way you do not mess up the name space and you can call each widget with its prefix. `tk.Button` or `ttk.Button` and so on. – Mike - SMT May 25 '18 at 19:24
  • Second I think you should move your 4 variables into your app instead of having them in the global namespace. However I do not have any database to test so this is hard to check on my end if its causing any issues or not. – Mike - SMT May 25 '18 at 19:28
  • can you provide some data you are expecting to receive from your `returns` variable? This way I have something to work with. – Mike - SMT May 25 '18 at 19:29
  • @Mike-SMT Uhhhh... Kinda. Im expecting a lot number, box order, Specification min, Specification max, Specification measurement 1 and 2, second spec min, second spec max, measurement 1 and 2. Production total, and scrap along with scrap reasons. After all is said and done most columns are blank though as the database has 3 different product types all of them taking different specification names. Thanks for the help :) – letto4135 May 25 '18 at 21:19
  • Can you write up one list of these items. So I can compile some fake ones. – Mike - SMT May 25 '18 at 21:22
  • AL, AL, 489AS, Part_Description, Part_Number, 489AT, Finished_Part_Number, 15.2, 16.8, 16, 16.1, 45 7/8, 46 1/8, 46, 46, blank, blank, blank, blank, blank, blank, blank, blank, blank, blank, blank, blank, and_so_on, 3.3, 450.8, 35, 3.3 Like that? – letto4135 May 25 '18 at 21:42
  • Yes that should suffice. Let me see what I can cook up. – Mike - SMT May 29 '18 at 12:49
  • Ok after playing around and searching some I think the answer to your original question is [HERE](https://stackoverflow.com/questions/14359906/horizontal-scrolling-wont-activate-for-ttk-treeview-widget). – Mike - SMT May 29 '18 at 13:22
  • Possible duplicate of [Horizontal scrolling won't activate for ttk Treeview widget](https://stackoverflow.com/questions/14359906/horizontal-scrolling-wont-activate-for-ttk-treeview-widget) – Mike - SMT May 29 '18 at 13:23
  • @Mike-SMT Still can't seem to get it.. Closer but not quite.. I have to increase the minwidth to the point that it looks absolutely barbaric to even get half the columns to actually show up. I wonder if there is a better way other than treeview. All i need to do is show a GUI of the entries in the database and be able to see all of the columns.. – letto4135 May 30 '18 at 20:46
  • You might be better off with managing labels instead of a treeview. I believe there are some limitations to tkinters treeview that is preventing you from getting exactly the behavior you are looking for. – Mike - SMT May 30 '18 at 20:48
  • I ended up pandas'ing it to excel for now :p Thanks for all your assistance, I appreciate it. – letto4135 May 30 '18 at 21:31

0 Answers0