I want to display multiple csv files (3 at least) in the same tkinter window but I have no clue how to do it. I have only found codes to display a single file in a window.
My current level in python is quite low (I'm a healthcare professional trying to do basic stuff) and it's basically adding together some code found online here and there but I still understand simple functions such as buttons and windows.
I have uploaded a picture to show more accurately what I'm aiming for: My goal in tkinter
Here is my current and my attempts so far:
from tkinter import *
import tkinter
import tkinter.ttk as ttk
from tkinter import Frame
import csv
root = tkinter.Tk()
root.title("Python - Healthcare continuity")
width = 500
height = 400
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x = (screen_width / 2) - (width / 2)
y = (screen_height / 2) - (height / 2)
root.geometry("%dx%d+%d+%d" % (width, height, x, y))
root.resizable(0, 0)
TableMargin = ttk.Frame(root)
TableMargin.grid(column=0, row=0, sticky=(N, W, E, S))
scrollbarx = Scrollbar(TableMargin, orient=HORIZONTAL)
scrollbary = Scrollbar(TableMargin, orient=VERTICAL)
# open file
with open("open(first.csv,'r+',encoding='utf-8')", newline = "") as file:
reader = csv.reader(file)
# r and c tell us where to grid the labels
r = 0
for col in reader:
c = 0
for row in col:
# i've added some styling
label = tkinter.Label(root, width = 10, height = 2, \
text = row, relief = tkinter.RIDGE)
label.grid(row = r, column = c)
c += 1
r += 1
with open("second.csv", newline = "") as file:
reader = csv.reader(file)
# r and c tell us where to grid the labels
r = 0
for col in reader:
c = 0
for row in col:
# i've added some styling
label = tkinter.Label(root, width = 10, height = 2, \
text = row, relief = tkinter.RIDGE)
label.grid(row = r, column = c)
c += 1
r += 1
with open("third.csv", newline = "") as file:
reader = csv.reader(file)
# r and c tell us where to grid the labels
r = 0
for col in reader:
c = 0
for row in col:
# i've added some styling
label = tkinter.Label(root, width = 10, height = 2, \
text = row, relief = tkinter.RIDGE)
label.grid(row = r, column = c)
c += 1
r += 1
root.mainloop()
Thank you for your help.