I'm trying to use customTkinter to display the contents of a MySQL database, but the placement of the table doesn't match the placement I've assigned in the grid. I'm pretty new to GUI Programming, so I'd love your help. Here's my code:
import customtkinter
import mysql.connector
import pandas as pd
from pandastable import Table, TableModel
conn = mysql.connector.connect(user='root', password='0000', host='localhost', database='python', auth_plugin='mysql_native_password')
cursor = conn.cursor()
class MyFrame(customtkinter.CTkFrame):
def __init__(self, master):
super().__init__(master)
self.header = customtkinter.CTkLabel(self, text="Dashboard", fg_color="transparent", font=("Product Sans",48))
self.header.grid(row=0, column=0, sticky="w")
command = "select * from fruits"
table_width = 310
table_height = 100
df = pd.read_sql_query(command, conn)
pt = Table(self, dataframe=df, width=table_width, height=table_height, showtoolbar=False, showstatusbar=False, showRowNumber=False)
pt.grid(row=310, column=0)
pt.show()
pt.hideRowHeader()
class App(customtkinter.CTk):
def __init__(self):
super().__init__()
self.title("my app")
self.geometry("1280x720")
self.grid_columnconfigure(0, weight=1)
self.grid_rowconfigure(0, weight=1)
self.frame = MyFrame(self)
self.frame.grid(row=0, column=0, sticky='nw')
self.frame.configure(width=1280, height=720)
self.button = customtkinter.CTkButton(self, text="my button")
self.button.grid(row=3, column=0, padx=10, pady=10, sticky="ew")
app = App()
app.mainloop()
Here's the output: output
I want the Table to be below the title 'Dashboard', but it attaches to the side and the scrollbar keeps glitching as well.
Note that
pandastable.Tablehas different parts which are put in the same parent frame (self, instance ofMyFramefor your case). One of the partrowindexheaderis put at row 0 and column 0 (same location of the label "Dashboard"). But it is hidden by callingpt.hideRowHeader()in your code, so you can see the label "Dashboard". If you remove the linept.hideRowHeader(), the label "Dashboard" will be covered by the row header.You can move the label "Dashboard" out of
MyFrameclass and create it inside same parent of instance ofMyFrameinstead.Below is a simplified example based on yours:
And the output: