Python Forum
sQlite3 output to tkinter treeview - how do I set / increase width of the output?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sQlite3 output to tkinter treeview - how do I set / increase width of the output?
#1
Hello,
Brand new to posting in this forum so hello all.

I do not seem to be able to increase the width of the output from an sQlite3 DB table.
The output is delivered in full, and I am clueless as to how to change it.
I'm sure the solution is straightforward. Too much of a newbie... any help very gratefully received.

This is my current output:
My current output




def showCustTable():
   showCustTableWin=Tk()
   showCustTableWin.title("* Customer Table *")
   showCustTableWin.geometry("850x350")
   showCustTableWin.wm_iconbitmap('favicon.ico')

   def View():
      myshop_db  = sqlite3.connect("myshop_db.db")
      c = myshop_db.cursor()
      c.execute('''SELECT * FROM Customers''')

      rows = c.fetchall()
      for row in rows:
         tree.insert("",tk.END, values = row)
      myshop_db.commit()
      myshop_db.close()

   frame1 = Frame(showCustTableWin, width=850, height=350,bd=15,relief="raise")
   frame1.pack()

   tree= ttk.Treeview(frame1, column=("column1", "column2", "column3", "column4", "column5", "column6", "column7"), show='headings')
   tree.heading("#1", text="CUST#")
   tree.column("#1", width = 5, anchor = "w")
   tree.heading("#2", text="NAME")
   tree.column("#2", width = 25, anchor = "w")
   tree.heading("#3", text="ADDRESS")
   tree.column("#3", width = 30, anchor = "w")
   tree.heading("#4", text="CITY")
   tree.column("#4", width = 15, anchor = "w")
   tree.heading("#5", text="POSTCODE")
   tree.column("#5", width = 15, anchor = "w")
   tree.heading("#6", text="TEL")
   tree.column("#6", width = 15, anchor = "w")
   tree.heading("#7", text="EMAIL")
   tree.column("#7", width = 35, anchor = "w")
   tree.pack()   
   View()
   
Again, thank you very much in advance for having a look. :)
Reply
#2
I have example of that in one o f my projects here: https://github.com/Larz60p/CaliforniaPublicSalaries
see src/CaCompGui.py for entire code
        self.download_tree = ttk.Treeview(frame3b,
                                          height=self.treeheight_download,
                                          padding=(2, 2, 2, 2),
                                          selectmode="extended")
        self.download_tree.heading('#0', text='Files to download',
                                   anchor=tk.CENTER)
        self.download_tree.column('#0', stretch=tk.YES, width=400)

        tree_down_scrolly = tk.Scrollbar(frame3b, orient=tk.VERTICAL,
                                         command=self.download_tree.yview)

        tree_down_scrolly.grid(row=0, rowspan=self.treeheight_download,
                               column=4, sticky='ns')

        tree_down_scrollx = tk.Scrollbar(frame3b, orient=tk.HORIZONTAL,
                                         command=self.download_tree.xview)
        tree_down_scrollx.grid(row=self.treeheight_download + 1, column=0,
                               columnspan=4, sticky='ew')
        self.download_tree.configure(yscroll=tree_down_scrolly)
        self.download_tree.configure(xscroll=tree_down_scrollx)
        self.download_tree.grid(row=0, rowspan=self.treeheight_download,
column=1, columnspan=3, sticky='nsew')
Reply
#3
Hey Larz60+,

Well it was that simple - thanks loads for that. Simply added "stretch=tk.YES" and expanded my width's and its done. Thank you for solving this for me. I can move on in my coding now. Much appreciated :)

I would like to see the whole code from your example above but couldn't find it using your link "src/CaCompGui.py". I'm not sure how do open it from there?

Thank you again,
:)
Reply
#4
Quote:I would like to see the whole code from your example above but couldn't find it using your link "src/CaCompGui.py". I'm not sure how do open it from there?
just go to start of project: https://github.com/Larz60p/CaliforniaPublicSalaries
click clone or download button and get it all.

There are three modules in src, you need the __init__.py even though it's empty
keep the file structure as it is, you will find another __init__.py file in the top directory, this is important as it tells the rest of the project where imports are located.
You can find a plethora of projects, and add your own, to pypi.org, each is usually backed up with a github repository, and can be downloaded to any directory by:
using git clone (need to install git once, see below).

The directory structure in this project works well if you use a virtual environment, which you should at some point start doing.

to see how to do this (virtual environment), look at the following tutorials:
If OS is Linux: https://python-forum.io/Thread-Part-1-Li...nvironment
For windows: https://python-forum.io/Thread-Part-2-Py...nt-Windows

Once you start using virtual environments, you will always use them because they make keeping projects isolated, and later packaging, much easier to do. Each can have it's own version of python, and only contain needed packages for the project.

Git:
You can install git for any platform here: https://git-scm.com/downloads
once you have installed git, you can clone any repository, including the one I mentioned in post 2, using the following (from command line):
  • Navigate to or create the directory where you wish to clone a package.
  • Clone using the following command (for the package I showed above)
    git clone https://github.com/Larz60p/CaliforniaPublicSalaries
  • That's all there is to it
Reply
#5
Really sorry, Larz,

Just realised I hadn't thanked you for your detailed and really helpful response. This is really kind and I'm rude.

I'm still wrestling with my program but this is a great help.

Thank you very much.. great work :)
Reply
#6
Your welcome anytime
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter Shell Terminal Or Shell Output sweetthdevil 5 8,762 Feb-03-2024, 02:51 PM
Last Post: Gribouillis
  tkinter - update/refresh treeview snakes 5 20,560 Dec-02-2023, 07:05 PM
Last Post: aynous19
  [PyGUI] How to format output from layout and keys thruss 2 2,737 Nov-30-2023, 08:11 AM
Last Post: sulo167
  send function output from one py file to another (OOP) lunacy90 15 2,298 Aug-26-2023, 02:42 PM
Last Post: deanhystad
  [Tkinter] How to insert data json to treeview tkinter? Shakanrose 8 4,217 Jan-19-2023, 03:58 PM
Last Post: Shakanrose
  [Tkinter] Different rows colours in treeview tkinter Krissstian 1 1,192 Nov-20-2022, 09:59 PM
Last Post: woooee
  [PyQt] Execute the script in remote and get the output maiya 2 1,368 Jul-10-2022, 05:03 AM
Last Post: maiya
  [Tkinter] About Tkinter Treeview.selection_get() usage. water 3 8,153 Feb-12-2022, 02:19 PM
Last Post: water
  [Tkinter] TKINTER quiz using sqlite3 database hezza_23 45 20,956 Nov-29-2021, 09:42 PM
Last Post: Hilal
  [Tkinter] [split] Is there a way to embed a treeview as a row inside another treeview? CyKlop 5 3,305 Oct-20-2021, 12:14 AM
Last Post: CyKlop

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020